package org.springblade.modules.platform.algorithm.method;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ht.utils.AbsoluteDeflection;
import com.ht.utils.CalModel5;
import com.ht.utils.RelativeDeflection;
import io.netty.channel.Channel;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import io.netty.util.AttributeKey;
import io.netty.util.concurrent.GlobalEventExecutor;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.platform.dto.Big3DScreenDTO;
import org.springblade.modules.platform.dto.DeviceRuningStateDTO;
import org.springblade.modules.platform.entity.*;
import org.springblade.modules.platform.mapper.EngineerValueRepairTableMapper;
import org.springblade.modules.platform.service.*;
import org.springblade.modules.platform.utils.TimeUtils;
import org.springblade.modules.platform.vo.*;
import org.springblade.modules.platform.vo.enums.BenchTypeNameEnum;
import org.springblade.modules.platform.vo.enums.DataStrategyEnum;
import org.springblade.modules.platform.vo.enums.PhysicalQuantityEnum;
import org.springblade.modules.platform.vo.enums.ProductTypeEnum;
import org.springblade.modules.platform.websocket.config.WebSokcetChannelGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Component
@AllArgsConstructor
@Slf4j
public class BaseStationMethod6 {
	private final IMeasuringChainPlatformTypeService iMeasuringChainPlatformTypeService;
	private final IMeasuringChainPlatformInfoService iMeasuringChainPlatformInfoService;
	private final IMeasuringPlatformTypeService iMeasuringPlatformTypeService;
	private final IDeviceTableService iDeviceTableService;
	private final IAbsolutelyValueTableService iAbsolutelyValueTableService;
	private final IPhysicalValueTableService iPhysicalValueTableService;//物理量数据
	private final IEngineerValueTableService iEngineerValueTableService;//工程量
	private final IMeasuringPointTableService iMeasuringPointTableService;//一侧量
	private final IEquipmentRuningStateService iEquipmentRuningStateService;
	private final ISysParameterService iSysParameterService;
	private final IProductModelPropertiesService productModelPropertiesService;
	private final IMeasuringChainTableService iMeasuringChainTableService;
	private final IArcsecondTableService iArcsecondTableService;
	private final BladeRedis bladeRedis;
	private static final AttributeKey<String> CONNECTION_ID = AttributeKey.valueOf("connectionId");

	/**
	 * 2号和17号倾角为0
	 * @param deviceRuningStateDTO
	 * @param gatherEvent
	 */
	public void installDeviceRuningState(DeviceRuningStateDTO deviceRuningStateDTO, Integer gatherEvent,Integer measuringTypeCode , Float zGame ) {
		try {
			Long acquisitionTime = deviceRuningStateDTO.getAcquisitionTime();//采集时间
			Long deptMeasuringInfoId = deviceRuningStateDTO.getDeptMeasuringInfoId();//测量链编号
			BigDecimal rietschlePressure = deviceRuningStateDTO.getRietschlePressure();//真空泵气压值
			List<DeviceRuningStateDTO.DeviceListDTO> deviceList = deviceRuningStateDTO.getDeviceList();//设备集合
			String acquisitionFlag = deviceRuningStateDTO.getAcquisitionFlag();
			String connectionId = deviceRuningStateDTO.getConnectionId();
			MeasuringChainTable byId = iMeasuringChainTableService.getById(deptMeasuringInfoId);

			List<MeasuringChainPlatformType> measuringChainPlatformTypeList = iMeasuringChainPlatformTypeService.getMeasuringChainPlatformTypeList(deptMeasuringInfoId);
			if(Func.isEmpty(measuringChainPlatformTypeList)){
				return;
			}

			BigDecimal i = new BigDecimal(65).divide(new BigDecimal(22),2,RoundingMode.HALF_UP);
			BigDecimal s = new BigDecimal(30);

			for (MeasuringChainPlatformType x : measuringChainPlatformTypeList) {
				if(Objects.equals(x.getMeasuringTypeCode(), measuringTypeCode)){

					MeasuringChainDetailsVO measuringChainDetailsVO = getMeasuringPlatform(x.getId(), deviceList,x.getMeasuringTypeCode(),acquisitionTime,s,connectionId,acquisitionFlag,i,deptMeasuringInfoId,zGame);
					if(measuringChainDetailsVO!=null){
						measuringChainDetailsVO.setGatherTime(acquisitionTime);
						measuringChainDetailsVO.setMeasurChainDirection(x.getMeasuringTypeCode());
						measuringChainDetailsVO.setRietschlePressure(rietschlePressure);
						measuringChainDetailsVO.setGatherEvent(gatherEvent);
						measuringChainDetailsVO.setMeasurChain(byId.getChainName());
						measuringChainDetailsVO.setMeasurChainCode(deptMeasuringInfoId);
						saveMeasuringChainDetails(measuringChainDetailsVO,acquisitionFlag);
						s = measuringChainDetailsVO.getI();
					}
				}
			}
			pullData(new BigDecimal(100),"计算完成",connectionId,200);

		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}

	}

	/**
	 * 计算测量连，所有侧台的工程量，物理量
	 * @param measuringTypeId
	 * @param deviceList
	 * @return
	 */
	private MeasuringChainDetailsVO getMeasuringPlatform(Long measuringTypeId,
														 List<DeviceRuningStateDTO.DeviceListDTO> deviceList,
														 Integer measuringTypeCode,
														 Long acquisitionTime,
														 BigDecimal s,
														 String connectionId,
														 String acquisitionFlag,  BigDecimal i,Long deptMeasuringInfoId, Float zGame  ){
		try {

			MeasuringChainDetailsVO measuringChainDetailsVO = new MeasuringChainDetailsVO();
			//排序以后所有配置的侧台
			List<MeasuringChainPlatformInfo> measuringChainPlatformInfo = iMeasuringChainPlatformInfoService.getMeasuringChainPlatformInfo(measuringTypeId);
			if(measuringChainPlatformInfo==null){
				return null;
			}
			List<MeasuringPlatformVO> list = new ArrayList<>();
			for (MeasuringChainPlatformInfo chainPlatformInfo : measuringChainPlatformInfo) {
				Long measuringPlatformId = chainPlatformInfo.getMeasuringPlatformId();//侧台编号
				MeasuringPlatformTypeVO measuringPlatformTypeVO = iMeasuringPlatformTypeService.deileMeasuringPlatformType(measuringPlatformId,  measuringTypeCode);//侧台所有计算策略
				Double yAxis = null;
				Long parentPlatformId = chainPlatformInfo.getParentPlatformId();
				if(parentPlatformId!=null){
					MeasuringChainPlatformInfo platformInfo = measuringChainPlatformInfo.stream().filter(x -> x.getMeasuringPlatformId().equals(parentPlatformId)).findFirst().get();
					yAxis = platformInfo.getyAxis();

				}
				MeasuringPlatformVO measuringPlatformVO = measuringPlatformCount(measuringPlatformTypeVO,
					deviceList,measuringTypeCode,
					chainPlatformInfo,list,acquisitionTime,s,connectionId,acquisitionFlag,deptMeasuringInfoId,yAxis,zGame);
				assert measuringPlatformVO != null;
				measuringPlatformVO.setMeasuringPlatformId(chainPlatformInfo.getMeasuringPlatformId());
				measuringPlatformVO.setMeasuringPlatformName(chainPlatformInfo.getMeasuringPlatformName());
				measuringPlatformVO.setBenchTypeCode(measuringPlatformTypeVO.getMeasuringPlatformType());
				measuringPlatformVO.setBenchTypeName(Objects.requireNonNull(BenchTypeNameEnum.getEnum(measuringPlatformTypeVO.getMeasuringPlatformType())).getMsg());
				measuringPlatformVO.setSort(chainPlatformInfo.getSort());
				list.add(measuringPlatformVO);
				s = s.add(i);

			}
			measuringChainDetailsVO.setMeasuringPlatformVOS(list);
			measuringChainDetailsVO.setMeasurChainCode(measuringTypeId);
			measuringChainDetailsVO.setI(s);
			return measuringChainDetailsVO;
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;

	}







	/**
	 * 单个侧台计算物理量，工程量
	 * @param measuringPlatformTypeVO
	 * @param deviceList
	 */
	private MeasuringPlatformVO measuringPlatformCount(MeasuringPlatformTypeVO measuringPlatformTypeVO,
													   List<DeviceRuningStateDTO.DeviceListDTO> deviceList,
													   Integer measuringTypeCode,
													   MeasuringChainPlatformInfo chainPlatformInfo,
													   List<MeasuringPlatformVO> measuringPlatformVOS,
													   Long acquisitionTime,
													   BigDecimal bi,
													   String connectionId,
													   String acquisitionFlag,
													   Long deptMeasuringInfoId,Double yAxis, Float zGame ){
		try {

			MeasuringPlatformConfigVO measuringPlatformConfigVO = null;
			List<MeasuringPlatformConfigVO> list1 = measuringPlatformTypeVO.getList();//如果没配置计算策略默认走计算
			if(!Func.isEmpty(list1)){
				measuringPlatformConfigVO = list1.get(0);
			}
			String measuringPlatformName = chainPlatformInfo.getMeasuringPlatformName();
			pullData(bi,"正在计算"+measuringPlatformName+".....",connectionId,200);
			switch (Objects.requireNonNull(BenchTypeNameEnum.getEnum(measuringPlatformTypeVO.getMeasuringPlatformType()))){
				case BASICS://基点测台
					List<OnceValueVO> onceValue1 = new ArrayList<>();
					Map<String,DeviceTableVO> mapd = new HashMap<>();
					List<String> list2 = Arrays.asList(measuringPlatformTypeVO.getDeviceId().split(","));
					list2.forEach(x->{
						DeviceTableVO deviceTableVO = iDeviceTableService.selectDeviceById(x);
						mapd.put(deviceTableVO.getDeviceChannelId(),deviceTableVO);
						String deviceChannelId = deviceTableVO.getDeviceChannelId();
						Optional<DeviceRuningStateDTO.DeviceListDTO> first = deviceList.stream().filter(l -> l.getDeviceId().equals(deviceChannelId)).findFirst();
						if(first.isPresent()){
							DeviceRuningStateDTO.DeviceListDTO deviceListDTO = first.get();//设备上报的本侧台的原始数据
							List<OnceValueVO> onceValue = getOnceValue(deviceListDTO, acquisitionTime,x,acquisitionFlag,measuringPlatformTypeVO.getCoordinatChannelId(),deviceList);
							onceValue1.addAll(onceValue);
						}

					});
					List<String> list = Arrays.asList(measuringPlatformTypeVO.getDeviceChannelId().split(","));

					AbsoluteValueVO absoluteValue = getAbsoluteValue(list,mapd, measuringPlatformConfigVO, deviceList,measuringPlatformTypeVO.getId(),acquisitionTime);//工程量
					List<String> stringList = absoluteValue.getStringList();
					if(!Func.isEmpty(stringList)){
						List<String> collect1 = stringList.stream().distinct().collect(Collectors.toList());
						collect1.forEach(c->{
							DeviceTableVO deviceTableVO = iDeviceTableService.selectDeviceById(c);
							String deviceChannelId = deviceTableVO.getDeviceChannelId();
							Optional<DeviceRuningStateDTO.DeviceListDTO> first = deviceList.stream().filter(l -> l.getDeviceId().equals(deviceChannelId)).findFirst();
							if(first.isPresent()){
								DeviceRuningStateDTO.DeviceListDTO deviceListDTO = first.get();//设备上报的本侧台的原始数据
								List<OnceValueVO> onceValue = getOnceValue(deviceListDTO, acquisitionTime,c,acquisitionFlag,measuringPlatformTypeVO.getCoordinatChannelId(),deviceList);
								onceValue1.addAll(onceValue);
							}
						});
					}
					/* onceValue1.addAll(onceValue5);*/
					return  MeasuringPlatformVO.builder().physicalQuantityVO(null).absoluteValueVO(absoluteValue).onceValueVOList(onceValue1).build();
				case ORDINARY://普通测台
					String deviceChannelId = measuringPlatformTypeVO.getDeviceChannelId();
					String deviceId = measuringPlatformTypeVO.getDeviceId();
					DeviceRuningStateDTO.DeviceListDTO deviceListDTO = null;
					Optional<DeviceRuningStateDTO.DeviceListDTO> first = deviceList.stream().filter(l -> l.getDeviceId().equals(deviceChannelId)).findFirst();
					if(first.isPresent()){
						deviceListDTO = first.get();//设备上报的本侧台的原始数据
					}else {
						//查询默认值
					}
					List<OnceValueVO> onceValue = getOnceValue(deviceListDTO, acquisitionTime,deviceId,acquisitionFlag,measuringPlatformTypeVO.getCoordinatChannelId(),deviceList);
					Long parentPlatformId = chainPlatformInfo.getParentPlatformId();//付侧台


					log.info("计算物理量开始:{}",measuringPlatformTypeVO.getMeasuringPlatformName());
					AbsoluteValueVO ordinaryAbsoluteValue;
					PhysicalQuantityVO physicalQuantity = getPhysicalQuantity(deviceListDTO, parentPlatformId, measuringTypeCode,deviceList,measuringPlatformTypeVO.getId(), deviceId, deptMeasuringInfoId,chainPlatformInfo.getMeasuringPlatformId());//物理量
					if(parentPlatformId!=null){
						MeasuringPlatformVO parentPlatformVO = measuringPlatformVOS.stream().filter(l -> l.getMeasuringPlatformId().equals(chainPlatformInfo.getParentPlatformId())).findFirst().get();//付侧台工程量和物理量

						if(measuringPlatformConfigVO==null){
							ordinaryAbsoluteValue = getOrdinaryAbsoluteValue(measuringPlatformTypeVO.getId(),measuringPlatformConfigVO, null, parentPlatformVO, chainPlatformInfo,physicalQuantity,measuringTypeCode,acquisitionTime,yAxis);//工程量
						}else {
							ordinaryAbsoluteValue = getOrdinaryAbsoluteValue(measuringPlatformTypeVO.getId(),measuringPlatformConfigVO, deviceList, parentPlatformVO, chainPlatformInfo, physicalQuantity,measuringTypeCode,acquisitionTime,yAxis);//工程量
						}
					}else {
						//需要知道高精度传感器的值
						ordinaryAbsoluteValue = getOrdinaryAbsoluteValue2(measuringPlatformConfigVO, deviceList,measuringTypeCode,acquisitionTime,  zGame );//高精度传感器带入
						//   ordinaryAbsoluteValue = AbsoluteValueVO.builder().x(0.0).y(0.0).z(0.0).alpha(0.0).beta(0.0).gama(0.0).build();
						physicalQuantity.setDipX(ordinaryAbsoluteValue.getAlpha());
						physicalQuantity.setDipY(ordinaryAbsoluteValue.getBeta());
					}
					List<String> stringList1 = ordinaryAbsoluteValue.getStringList();
					if(!Func.isEmpty(stringList1)){
						List<String> collect1 = stringList1.stream().distinct().collect(Collectors.toList());
						collect1.forEach(c->{
							DeviceTableVO deviceTableVO = iDeviceTableService.selectDeviceById(c);
							Optional<DeviceRuningStateDTO.DeviceListDTO> first1 = deviceList.stream().filter(l -> l.getDeviceId().equals(deviceTableVO.getDeviceChannelId())).findFirst();
							if(first1.isPresent()){
								DeviceRuningStateDTO.DeviceListDTO deviceListDTO1 = first1.get();//设备上报的本侧台的原始数据
								List<OnceValueVO> onceValue2 = getOnceValue(deviceListDTO1, acquisitionTime,c,acquisitionFlag,measuringPlatformTypeVO.getCoordinatChannelId(),deviceList);
								onceValue.addAll(onceValue2);
							}
						});
					}

					log.info("侧台名称:{}",measuringPlatformTypeVO.getMeasuringPlatformName());
					log.info("物理量:{}",physicalQuantity);
					log.info("工程量:{}",ordinaryAbsoluteValue);
					/*   onceValue.addAll(onceValue5);*/
					return  MeasuringPlatformVO.builder().physicalQuantityVO(physicalQuantity).absoluteValueVO(ordinaryAbsoluteValue).onceValueVOList(onceValue).build();
			}

			return null;
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;


	}
	/**
	 *普通侧台工程量
	 * @param measuringPlatformConfigVO(测量连方向)
	 * @param deviceList（父侧台工程量）
	 * @return
	 */
	private AbsoluteValueVO getOrdinaryAbsoluteValue2(MeasuringPlatformConfigVO measuringPlatformConfigVO,
													  List<DeviceRuningStateDTO.DeviceListDTO> deviceList,Integer measuringTypeCode,Long gatherTime,
													  Float zGame ){//1正向 2逆向

		try {

			Double alpha =0.0;
			Double beta = 0.0;
			Double gama = 0.0;
			Double x = 0.0;
			Double y = 0.0;
			Double z = 0.0;
			//需要自己的通道ID
			Long measuringPlatformId = measuringPlatformConfigVO.getMeasuringPlatformId();//侧台ID
			List<String> strings = new ArrayList<>();
			if(measuringPlatformConfigVO!=null){//走配置的策略

				Integer xType = measuringPlatformConfigVO.getxType();
				if(xType!=null){
					if(xType.equals(DataStrategyEnum.MANUAL.getCode())){
						x = Double.parseDouble(measuringPlatformConfigVO.getxValue());
					}else {
						//未给出结算规则
					}
				}
				Integer yType = measuringPlatformConfigVO.getyType();
				if(yType!=null){
					if(yType.equals(DataStrategyEnum.MANUAL.getCode())){
						y = Double.parseDouble(measuringPlatformConfigVO.getyValue());
					}else {
						//未给出结算规则
					}
				}
				Integer zType = measuringPlatformConfigVO.getzType();
				if(zType!=null){
					if(zType.equals(DataStrategyEnum.MANUAL.getCode())){
						z = Double.parseDouble(measuringPlatformConfigVO.getzValue());
					}else {
						//未给出结算规则
					}
				}
				Map<String, Double> dataStrategy = null;
				Integer alphaType = measuringPlatformConfigVO.getAlphaType();
				if(alphaType!=null){
					if(alphaType.equals(DataStrategyEnum.MANUAL.getCode())){
						alpha = Double.parseDouble(measuringPlatformConfigVO.getAlphaValue());
					}else if(alphaType.equals(DataStrategyEnum.COMPANY.getCode())){
						dataStrategy =  getDataStrategy(measuringPlatformConfigVO.getMeasuringPlatformId(),measuringPlatformConfigVO.getAlphaValue(),measuringPlatformConfigVO.getPlatformTypeCode(),deviceList);//ccd1AfterDipx1

						alpha = dataStrategy.get("dipX");
						strings.add(measuringPlatformConfigVO.getAlphaValue());
					}
				}
				Integer betaType = measuringPlatformConfigVO.getBetaType();
				if(betaType!=null){
					if(betaType.equals(DataStrategyEnum.MANUAL.getCode())){
						beta = Double.parseDouble(measuringPlatformConfigVO.getBetaValue());
					}else if(betaType.equals(DataStrategyEnum.COMPANY.getCode())){
						beta = dataStrategy.get("dipY");
						strings.add(measuringPlatformConfigVO.getBetaValue());
					}
				}
				Integer gamaType = measuringPlatformConfigVO.getGamaType();
				if(gamaType!=null){
					if(gamaType.equals(DataStrategyEnum.MANUAL.getCode())){
						gama = Double.parseDouble(measuringPlatformConfigVO.getGamaValue());
					}else if(gamaType.equals(DataStrategyEnum.COMPANY.getCode())){
						//没有提供算法
					}
				}
			}

			List<ArcsecondTable> list = iArcsecondTableService.list(Wrappers.<ArcsecondTable>lambdaQuery()
				.eq(ArcsecondTable::getGatherTime, gatherTime)
				.eq(ArcsecondTable::getMeasuringeCode, measuringTypeCode)
				.eq(ArcsecondTable::getType, 2)
				.eq(ArcsecondTable::getArcsecondType, 1));
			if(Func.isNotEmpty(list)){
				ArcsecondTable arcsecondTable = list.stream()
					.min(Comparator.comparingDouble(obj -> Math.abs(obj.getDifferenceValue()))).orElse(null);
				gama = arcsecondTable.getGama();
				log.info("最终的1号侧台的game值为:{}",gama);
				bladeRedis.set("device:game:" + measuringTypeCode,arcsecondTable.getArcsecondValue());
			}else{
				gama =  4.85E-6 * zGame;
				bladeRedis.set("device:game:" + measuringTypeCode,zGame);
			}

			log.info("程量为:{}",AbsoluteValueVO.builder().x(x).y(y).z(z).alpha(alpha).beta(beta).gama(gama).stringList(strings).build());
			return AbsoluteValueVO.builder().x(x).y(y).z(z).alpha(alpha).beta(beta).gama(gama).stringList(strings).build();
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;


	}


	/**
	 *普通侧台工程量
	 * @param measuringPlatformConfigVO(测量连方向)
	 * @param deviceList（父侧台工程量）
	 * @param parentPlatformVO（本侧台的工程量）
	 * @param chainPlatformInfo（本侧台的物理量）
	 * @return
	 */
	private AbsoluteValueVO getOrdinaryAbsoluteValue(Long measuringPlatformId,MeasuringPlatformConfigVO measuringPlatformConfigVO,
													 List<DeviceRuningStateDTO.DeviceListDTO> deviceList,
													 MeasuringPlatformVO parentPlatformVO,
													 MeasuringChainPlatformInfo chainPlatformInfo,
													 PhysicalQuantityVO physicalQuantity,
													 Integer measuringTypeCode,Long acquisitionTime,Double yAxis){
		try {

			AbsoluteValueVO absoluteValueVO = parentPlatformVO.getAbsoluteValueVO();
			Double x;
			Double y;
			Double z;
			Double alpha;
			Double beta;
			Double gama;
			PhysicalQuantityVO physicalQuantityVO = parentPlatformVO.getPhysicalQuantityVO();//付侧台的物理量
			Boolean dir = Objects.equals(measuringTypeCode,1);//测量连方向

			AbsoluteDeflection parentDeflect = new AbsoluteDeflection();//父侧台工程量
			parentDeflect.setZ(absoluteValueVO.getZ());
			parentDeflect.setX(absoluteValueVO.getX());
			parentDeflect.setY(absoluteValueVO.getY());
			parentDeflect.setAlpha(absoluteValueVO.getAlpha());
			parentDeflect.setBeta(absoluteValueVO.getBeta());
			parentDeflect.setGama(absoluteValueVO.getGama());


			AbsoluteDeflection childDeflect = new AbsoluteDeflection();//本侧台的工程量
			childDeflect.setBeta(physicalQuantity.getDipY());
			childDeflect.setAlpha(physicalQuantity.getDipX());

			RelativeDeflection relativeDeflect = new RelativeDeflection();//本侧台的物理量
			relativeDeflect.setNX(physicalQuantity.getNX());
			relativeDeflect.setNZ(physicalQuantity.getNZ());
			relativeDeflect.setZX(physicalQuantity.getZX());
			relativeDeflect.setZZ(physicalQuantity.getZZ());


			if(!dir){//如果是逆向的时候DeltaY取父级测台的DeltaY
				Double deltaY = physicalQuantityVO.getDeltaY();
				relativeDeflect.setDeltaY(deltaY);
			}else {
				relativeDeflect.setDeltaY(physicalQuantity.getDeltaY());
				/*		childDeflect.setAlpha(physicalQuantity.getDipX() * -1.0);*/
			}

			CalModel5 calModel = new CalModel5();
			AbsoluteDeflection cal = calModel.cal(dir,
				parentDeflect,
				childDeflect,
				relativeDeflect,
				chainPlatformInfo.getyAxis(),
				chainPlatformInfo.getPreviousDistance(),
				chainPlatformInfo.getxAxis(),yAxis);
			z = cal.getZ();
			x = cal.getX();
			alpha  = cal.getAlpha();
			y = cal.getBeta();
			beta = physicalQuantityVO.getDipY();
			gama = cal.getGama();
			List<String> strings = new ArrayList<>();
			if(measuringPlatformConfigVO!=null){//走配置的策略

				Integer xType = measuringPlatformConfigVO.getxType();
				if(xType!=null){
					if(xType.equals(DataStrategyEnum.MANUAL.getCode())){
						x = Double.parseDouble(measuringPlatformConfigVO.getxValue());
					}else {
						//未给出结算规则
					}
				}
				Integer yType = measuringPlatformConfigVO.getyType();
				if(yType!=null){
					if(yType.equals(DataStrategyEnum.MANUAL.getCode())){
						y = Double.parseDouble(measuringPlatformConfigVO.getyValue());
					}else {
						//未给出结算规则
					}
				}
				Integer zType = measuringPlatformConfigVO.getzType();
				if(zType!=null){
					if(zType.equals(DataStrategyEnum.MANUAL.getCode())){
						z = Double.parseDouble(measuringPlatformConfigVO.getzValue());
					}else {
						//未给出结算规则
					}
				}
				Map<String, Double> dataStrategy;
				Integer alphaType = measuringPlatformConfigVO.getAlphaType();
				if(alphaType!=null){
					if(alphaType.equals(DataStrategyEnum.MANUAL.getCode())){
						alpha = Double.parseDouble(measuringPlatformConfigVO.getAlphaValue());
					}else if(alphaType.equals(DataStrategyEnum.COMPANY.getCode())){
						dataStrategy =  getDataStrategy(measuringPlatformConfigVO.getMeasuringPlatformId(),measuringPlatformConfigVO.getAlphaValue(),measuringPlatformConfigVO.getPlatformTypeCode(),deviceList);//ccd1AfterDipx1
						alpha = dataStrategy.get("dipX");

						strings.add(measuringPlatformConfigVO.getAlphaValue());
					}
				}
				Integer betaType = measuringPlatformConfigVO.getBetaType();
				if(betaType!=null){
					if(betaType.equals(DataStrategyEnum.MANUAL.getCode())){
						beta = Double.parseDouble(measuringPlatformConfigVO.getBetaValue());
					}else if(betaType.equals(DataStrategyEnum.COMPANY.getCode())){
						dataStrategy = getDataStrategy(measuringPlatformConfigVO.getMeasuringPlatformId(),measuringPlatformConfigVO.getBetaValue(), measuringPlatformConfigVO.getPlatformTypeCode(), deviceList);
						beta = dataStrategy.get("dipY");
						strings.add(measuringPlatformConfigVO.getBetaValue());
					}
				}
				Integer gamaType = measuringPlatformConfigVO.getGamaType();
				if(gamaType!=null){
					if(gamaType.equals(DataStrategyEnum.MANUAL.getCode())){
						gama = Double.parseDouble(measuringPlatformConfigVO.getGamaValue());
					}else if(gamaType.equals(DataStrategyEnum.COMPANY.getCode())){
						//没有提供算法
					}
				}
			}
			return AbsoluteValueVO.builder().x(x).y(y).z(z).alpha(alpha).beta(beta).gama(gama).stringList(strings).build();
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;

	}
	/**
	 * 普通测台计算物理量
	 * @param deviceListDTO
	 * @param parentPlatformId
	 * @return
	 */
	private PhysicalQuantityVO getPhysicalQuantity(DeviceRuningStateDTO.DeviceListDTO deviceListDTO,
												   Long parentPlatformId,
												   Integer measuringTypeCode,
												   List<DeviceRuningStateDTO.DeviceListDTO> deviceList,Long id,String deviceId,Long deptMeasuringInfoId,Long measuringPlatformId){

		try {
			List<SysParameter> sysParameterList = iSysParameterService.list(Wrappers.<SysParameter>query().lambda().eq(SysParameter::getMeasuringPlatformId,id));
			List<DeviceRuningStateDTO.DeviceListDTO.AttributeListDTO> attributeListDTO = deviceListDTO.getAttributeListDTO();
			MeasuringPlatformTypeVO parentPlatformTypeVO = iMeasuringPlatformTypeService.deileMeasuringPlatformType(parentPlatformId,measuringTypeCode);
			if(parentPlatformTypeVO!=null&&Objects.equals(parentPlatformTypeVO.getMeasuringPlatformType(), BenchTypeNameEnum.BASICS.getCode())){//付侧台位基点侧台

				AbsolutelyValueTable one = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
					.eq(AbsolutelyValueTable::getDeptId,deviceId)
					.eq(AbsolutelyValueTable::getMeasurChainDirection,measuringTypeCode));
				Integer ccd3_after_tangential_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_after_tangential_y")).findFirst().get().getValue();
				Integer ccd3_front_tangential_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_front_tangential_y")).findFirst().get().getValue();
				// Double deltaY = baseStationAlgorithm.getDeformation(ccd3_after_tangential_y,ccd3_front_tangential_y);
				Double deltaY = getModelData(Arrays.asList(ccd3_after_tangential_y, ccd3_front_tangential_y), sysParameterList,PhysicalQuantityEnum.DELTAY);

				Integer ccd1_after_dip_x = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_after_dip_y")).findFirst().get().getValue();
				Integer ccd1_front_dip_x = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_front_dip_y")).findFirst().get().getValue();
				//Double dipX = (ccd1_after_dip_x + ccd1_front_dip_x) / 2 * 0.0047 / 2000;
				Double dipX = getModelData(Arrays.asList(ccd1_after_dip_x, ccd1_front_dip_x), sysParameterList,PhysicalQuantityEnum.DIPX);


				Integer ccd2_after_dip_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_after_dip_x")).findFirst().get().getValue();
				Integer ccd2_front_dip_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_front_dip_x")).findFirst().get().getValue();
				//  Double dipY = (ccd2_after_dip_y+ ccd2_front_dip_y ) / 2 * 0.0047 / 2000;
				Double dipY = getModelData(Arrays.asList(ccd2_after_dip_y, ccd2_front_dip_y), sysParameterList,PhysicalQuantityEnum.DIPY);
				if(one==null){
					one = new AbsolutelyValueTable();
					one.setMeasurChainCode(deptMeasuringInfoId);
					one.setMeasurChainDirection(measuringTypeCode);
					one.setDeptId(deviceId);
					one.setzX(0.0);
					one.setnX(0.0);
					one.setzZ(0.0);
					one.setnZ(0.0);


					one.setDipY(dipY);
					one.setDipX(dipX);
					one.setDeltaY(deltaY);
					one.setInsertTime(System.currentTimeMillis());
					iAbsolutelyValueTableService.save(one);
				}
				dipY = dipY - one.getDipY();
				dipX = dipX - one.getDipX();
				deltaY = deltaY - one.getDeltaY();
				return PhysicalQuantityVO.builder().zX(0.0).nZ(0.0).zZ(0.0).zZ(0.0).nX(0.0).deltaY(deltaY).dipX(dipX).dipY(dipY).build();
			}else {
				AbsolutelyValueTable one = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
					.eq(AbsolutelyValueTable::getDeptId,deviceId)
					.eq(AbsolutelyValueTable::getMeasurChainDirection,measuringTypeCode));


				if(measuringTypeCode==1){//正向
					if(parentPlatformId==null){
						Double dipY = 0.0;
						Double deltaY = 0.0;
						Double dipX = 0.0;
						if(one==null){
							one = new AbsolutelyValueTable();
							one.setMeasurChainCode(deptMeasuringInfoId);
							one.setMeasurChainDirection(measuringTypeCode);
							one.setDeptId(deviceId);
							one.setzX(0.0);
							one.setnX(0.0);
							one.setzZ(0.0);
							one.setnZ(0.0);
							one.setDipY(0.0);
							one.setDipX(0.0);
							one.setDeltaY(0.0);
							one.setInsertTime(System.currentTimeMillis());
							iAbsolutelyValueTableService.save(one);
						}
						dipY = dipY - one.getDipY();
						dipX = dipX - one.getDipX();
						deltaY = deltaY - one.getDeltaY();
						return PhysicalQuantityVO.builder().zX(0.0).nZ(0.0).zZ(0.0).zZ(0.0).nX(0.0).deltaY(deltaY).dipX(dipX).dipY(dipY).build();
					}


					Integer ccd1_x_front_forward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_x_front_forward")).findFirst().get().getValue();
					Integer ccd1_x_after_forward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_x_after_forward")).findFirst().get().getValue();
					Integer ccd4_x_after_forward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd4_x_after_forward")).findFirst().get().getValue();
					Integer ccd4_x_front_forward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd4_x_front_forward")).findFirst().get().getValue();
					// Double zx = baseStationAlgorithm.getPhysicalQuantityFormula(ccd1_x_after_forward, ccd1_x_front_forward, ccd4_x_after_forward, ccd4_x_front_forward);
					log.info("zxccd值:{}",Arrays.asList(ccd1_x_after_forward, ccd1_x_front_forward,ccd4_x_after_forward,ccd4_x_front_forward));
					Double zx = getModelData(Arrays.asList(ccd1_x_after_forward, ccd1_x_front_forward,ccd4_x_after_forward,ccd4_x_front_forward), sysParameterList,PhysicalQuantityEnum.ZX);
					log.info("zxccd值:{}",Arrays.asList(ccd1_x_after_forward,ccd4_x_after_forward));
					Double zx2 = getModelData(Arrays.asList(ccd1_x_after_forward,ccd4_x_after_forward), sysParameterList,PhysicalQuantityEnum.ZX);
					log.info("zxccd值:{}",Arrays.asList(ccd1_x_front_forward,ccd4_x_front_forward));
					Double zx3 = getModelData(Arrays.asList( ccd1_x_front_forward,ccd4_x_front_forward), sysParameterList,PhysicalQuantityEnum.ZX);

					//单独计算前沿  和单独计算后延

					Integer ccd2_z_after_forward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_z_after_forward")).findFirst().get().getValue();
					Integer ccd2_z_front_forward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_z_front_forward")).findFirst().get().getValue();
					Integer ccd3_z_after_forward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_z_after_forward")).findFirst().get().getValue();
					Integer ccd3_z_front_forward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_z_front_forward")).findFirst().get().getValue();
					// Double zz = baseStationAlgorithm.getPhysicalQuantityFormula(ccd2_z_after_forward, ccd2_z_front_forward, ccd3_z_after_forward, ccd3_z_front_forward);
					Double zz = getModelData(Arrays.asList(ccd2_z_after_forward, ccd2_z_front_forward,ccd3_z_after_forward,ccd3_z_front_forward), sysParameterList,PhysicalQuantityEnum.ZZ);
					Double zz2 = getModelData(Arrays.asList(ccd2_z_after_forward,ccd3_z_after_forward), sysParameterList,PhysicalQuantityEnum.ZZ);
					Double zz3 = getModelData(Arrays.asList(ccd2_z_front_forward,ccd3_z_front_forward), sysParameterList,PhysicalQuantityEnum.ZZ);



					String deviceChannelId = parentPlatformTypeVO.getDeviceChannelId();
					List<DeviceRuningStateDTO.DeviceListDTO.AttributeListDTO> parentDTO = null;
					Optional<DeviceRuningStateDTO.DeviceListDTO> first = deviceList.stream().filter(l -> l.getDeviceId().equals(deviceChannelId)).findFirst();
					if(first.isPresent()){
						parentDTO = first.get().getAttributeListDTO();
					}else {
						//读取默认值
					}
					assert parentDTO != null;

					//List<MeasuringPlatformConfigVO> list = parentPlatformTypeVO.getList();
					//高精度传感器带入计算的


					Integer ccd1_x_after_backward = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_x_after_backward")).findFirst().get().getValue();
					Integer ccd1_x_front_backward = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_x_front_backward")).findFirst().get().getValue();
					Integer ccd4_x_after_backward = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd4_x_after_backward")).findFirst().get().getValue();
					Integer ccd4_x_front_backward = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd4_x_front_backward")).findFirst().get().getValue();

					List<SysParameter> parentSysParameterList = iSysParameterService.list(Wrappers.<SysParameter>query().lambda().eq(SysParameter::getMeasuringPlatformId, parentPlatformTypeVO.getId()));

					Double nx = getModelData(Arrays.asList(ccd1_x_after_backward, ccd1_x_front_backward,ccd4_x_after_backward,ccd4_x_front_backward), parentSysParameterList,PhysicalQuantityEnum.NX);
					Double nx2 = getModelData(Arrays.asList(ccd1_x_after_backward,ccd4_x_after_backward), parentSysParameterList,PhysicalQuantityEnum.NX);
					Double nx3 = getModelData(Arrays.asList( ccd1_x_front_backward,ccd4_x_front_backward), parentSysParameterList,PhysicalQuantityEnum.NX);

					//CCD2-Z脉冲后沿-后向位移
					Integer ccd2_z_after_backward = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_z_after_backward")).findFirst().get().getValue();
					//CCD2-Z脉冲前沿-后向位移
					Integer ccd2_z_front_backward = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_z_front_backward")).findFirst().get().getValue();
					//CCD3-Z脉冲后沿-后向位移
					Integer ccd3_z_after_backward = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_z_after_backward")).findFirst().get().getValue();
					//CCD3-Z脉冲前沿-后向位移
					Integer ccd3_z_front_backward = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_z_front_backward")).findFirst().get().getValue();

					Double nz = getModelData(Arrays.asList(ccd2_z_after_backward, ccd2_z_front_backward,ccd3_z_after_backward,ccd3_z_front_backward), parentSysParameterList,PhysicalQuantityEnum.NZ);
					Double nz2 = getModelData(Arrays.asList(ccd2_z_after_backward,ccd3_z_after_backward), parentSysParameterList,PhysicalQuantityEnum.NZ);
					Double nz3 = getModelData(Arrays.asList(ccd2_z_front_backward,ccd3_z_front_backward), parentSysParameterList,PhysicalQuantityEnum.NZ);


					Integer ccd3_after_tangential_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_after_tangential_y")).findFirst().get().getValue();
					Integer ccd3_front_tangential_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_front_tangential_y")).findFirst().get().getValue();

					Integer ccd2_after_dip_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_after_dip_y")).findFirst().get().getValue();
					Integer ccd2_front_dip_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_front_dip_y")).findFirst().get().getValue();

					Integer ccd1_after_dip_x = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_after_dip_x")).findFirst().get().getValue();
					Integer ccd1_front_dip_x = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_front_dip_x")).findFirst().get().getValue();

					if(one==null){
						one = new AbsolutelyValueTable();
						one.setMeasurChainCode(deptMeasuringInfoId);
						one.setMeasurChainDirection(measuringTypeCode);
						one.setDeptId(deviceId);
						one.setzX(zx);
						one.setzZ(zz);
						one.setnX(nx);
						one.setnZ(nz);

						one.setCcd2FrontDipY(ccd2_front_dip_y);
						one.setCcd2AfterDipY(ccd2_after_dip_y);

						one.setCcd1AfterDipX(ccd1_after_dip_x);
						one.setCcd1FrontDipX(ccd1_front_dip_x);

						one.setCcd3AfterTangentialY(ccd3_after_tangential_y);
						one.setCcd3FrontTangentialY(ccd3_front_tangential_y);

						one.setInsertTime(System.currentTimeMillis());
						iAbsolutelyValueTableService.save(one);
						return PhysicalQuantityVO.builder().nZ(0.0).zX(0.0).zZ(0.0).nX(0.0).deltaY(0.0).dipY(0.0).dipX(0.0).build();
					}

					zx = zx - one.getzX();
					zz = zz - one.getzZ();
					nx = nx - one.getnX();
					nz = nz - one.getnZ();

					//zx =  getDobleMath(zx - one.getzX(),zx2 - one.getzX(),zx3 - one.getzX());
					//zz = getDobleMath(zz - one.getzZ(), zz2 - one.getzZ(), zz3 - one.getzZ());
					//nx = getDobleMath(nx - one.getnX(), nx2 - one.getnX(), nx3 - one.getnX());
					//nz = getDobleMath(nz - one.getnZ(), nz2 - one.getnZ(), nz3 - one.getnZ());


					List<Double> dobleMath1 = getDobleMath2(ccd3_front_tangential_y , ccd3_after_tangential_y ,one.getCcd3FrontTangentialY(),one.getCcd3AfterTangentialY());
					Double deltaY = getModelData2(dobleMath1.get(0), sysParameterList, PhysicalQuantityEnum.DELTAY)
						- getModelData2(dobleMath1.get(1), sysParameterList, PhysicalQuantityEnum.DELTAY);

					double dipX;
					if(ccd2_after_dip_y>7000||(ccd2_after_dip_y<=500&&ccd2_after_dip_y>0)&&(ccd2_front_dip_y<7000&&ccd2_front_dip_y>500)){//异常点
						dipX = getModelData2(Double.valueOf(ccd2_front_dip_y), sysParameterList, PhysicalQuantityEnum.DIPY)
							- getModelData2(Double.valueOf(one.getCcd2FrontDipY()), sysParameterList, PhysicalQuantityEnum.DIPY);
					}else if(ccd2_front_dip_y>7000||(ccd2_front_dip_y<=500&&ccd2_front_dip_y>0)&&(ccd2_after_dip_y<7000&&ccd2_after_dip_y>500)){
						dipX = getModelData2(Double.valueOf(ccd2_after_dip_y), sysParameterList, PhysicalQuantityEnum.DIPY)
							- getModelData2(Double.valueOf(one.getCcd2AfterDipY()), sysParameterList, PhysicalQuantityEnum.DIPY);
					}else {
						List<Double> dobleMath2 = getDobleMath2(ccd2_after_dip_y , ccd2_front_dip_y,one.getCcd2AfterDipY(),one.getCcd2FrontDipY());
						dipX = getModelData2(dobleMath2.get(0), sysParameterList, PhysicalQuantityEnum.DIPY)
							- getModelData2(dobleMath2.get(1), sysParameterList, PhysicalQuantityEnum.DIPY);
					}




					List<Double> dobleMath3 = getDobleMath2(ccd1_front_dip_x , ccd1_after_dip_x,one.getCcd1FrontDipX() ,one.getCcd1AfterDipX());
					Double dipY = getModelData2(dobleMath3.get(0), sysParameterList,PhysicalQuantityEnum.DIPX)
						- getModelData2(dobleMath3.get(1), sysParameterList, PhysicalQuantityEnum.DIPX);
					Double x26 = null;
					Double y25 = null;
					Double x28= null;
					Double y27= null;
					Double x29= null;
					Double y30= null;
					Double x32= null;
					Double y31= null;
					Double y33= null;
					Double x34= null;
					MeasuringPlatformType byId = iMeasuringPlatformTypeService.getById(measuringPlatformId);
					if(Func.isNotEmpty(byId.getCoordinatChannelId())){
						if(byId.getCoordinatChannelId().contains("25")){
							AbsolutelyValueTable one1 = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
							.eq(AbsolutelyValueTable::getMeasurChainDirection, measuringTypeCode).eq(AbsolutelyValueTable::getBenchTypeCode, 2526));//正
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO3 = deviceList.stream().filter(l -> l.getDeviceId().equals("26")).findFirst().orElse(null);
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO4 = deviceList.stream().filter(l -> l.getDeviceId().equals("25")).findFirst().orElse(null);
						x26 = Double.parseDouble(deviceListDTO3.getAttributeListDTO().get(0).getValue().toString());
						y25 = Double.parseDouble(deviceListDTO4.getAttributeListDTO().get(0).getValue().toString());


						if(one1==null){
							one1 = new AbsolutelyValueTable();
							one1.setBenchTypeCode(2526);
							one1.setY(y25);
							one1.setDipX(x26);
							one1.setMeasurChainDirection(measuringTypeCode);
							iAbsolutelyValueTableService.save(one1);
						}
						x26 = (((x26 - one1.getDipX()) / 100 )  * -1);
						y25 = ((y25 - one1.getY()) / 100 );


						AbsolutelyValueTable nOne = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
							.eq(AbsolutelyValueTable::getMeasurChainDirection, measuringTypeCode).eq(AbsolutelyValueTable::getBenchTypeCode, 2728));//dao
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO27 = deviceList.stream().filter(l -> l.getDeviceId().equals("28")).findFirst().orElse(null);
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO28 = deviceList.stream().filter(l -> l.getDeviceId().equals("27")).findFirst().orElse(null);
						double x2728 = Double.parseDouble(deviceListDTO27.getAttributeListDTO().get(0).getValue().toString());
						double y2728 = Double.parseDouble(deviceListDTO28.getAttributeListDTO().get(0).getValue().toString());

						if(nOne==null){
							nOne = new AbsolutelyValueTable();
							nOne.setBenchTypeCode(2728);
							nOne.setY(y2728);
							nOne.setDipX(x2728);
							nOne.setMeasurChainDirection(measuringTypeCode);
							iAbsolutelyValueTableService.save(nOne);
						}
						x28 =  (((x2728 - nOne.getDipX()) / 100 )* -1);
						y27 =  (((y2728 - nOne.getY()) / 100 )* -1);


						AbsolutelyValueTable nOne29 = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
							.eq(AbsolutelyValueTable::getMeasurChainDirection, measuringTypeCode).eq(AbsolutelyValueTable::getBenchTypeCode, 2930));//dao
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO29 = deviceList.stream().filter(l -> l.getDeviceId().equals("29")).findFirst().orElse(null);
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO30 = deviceList.stream().filter(l -> l.getDeviceId().equals("30")).findFirst().orElse(null);
						x29 = Double.parseDouble(deviceListDTO29.getAttributeListDTO().get(0).getValue().toString());
						y30 = Double.parseDouble(deviceListDTO30.getAttributeListDTO().get(0).getValue().toString());


						if(nOne29==null){
							nOne29 = new AbsolutelyValueTable();
							nOne29.setBenchTypeCode(2930);
							nOne29.setY(y30);
							nOne29.setDipX(x29);
							nOne29.setMeasurChainDirection(measuringTypeCode);
							iAbsolutelyValueTableService.save(nOne29);
						}
						x29 =  (((x29 - nOne29.getDipX()) / 100 ) * -1);
						y30 =  (((y30 - nOne29.getY()) / 100 )* -1);


						AbsolutelyValueTable nOne3132 = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
							.eq(AbsolutelyValueTable::getMeasurChainDirection, measuringTypeCode).eq(AbsolutelyValueTable::getBenchTypeCode, 3132));//dao
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO32 = deviceList.stream().filter(l -> l.getDeviceId().equals("32")).findFirst().orElse(null);
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO31 = deviceList.stream().filter(l -> l.getDeviceId().equals("31")).findFirst().orElse(null);
						x32 = Double.parseDouble(deviceListDTO32.getAttributeListDTO().get(0).getValue().toString());
						y31 = Double.parseDouble(deviceListDTO31.getAttributeListDTO().get(0).getValue().toString());

						if(nOne3132==null){
							nOne3132 = new AbsolutelyValueTable();
							nOne3132.setBenchTypeCode(3132);
							nOne3132.setY(y31);
							nOne3132.setDipX(x32);
							nOne3132.setMeasurChainDirection(measuringTypeCode);
							iAbsolutelyValueTableService.save(nOne3132);
						}
						x32 =  (((x32 - nOne3132.getDipX()) / 100 ) * -1);
						y31 =  ((y31 - nOne3132.getY()) / 100 );


						AbsolutelyValueTable nOne3334 = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
							.eq(AbsolutelyValueTable::getMeasurChainDirection, measuringTypeCode).eq(AbsolutelyValueTable::getBenchTypeCode, 3334));//dao
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO33 = deviceList.stream().filter(l -> l.getDeviceId().equals("33")).findFirst().orElse(null);//Y
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO34 = deviceList.stream().filter(l -> l.getDeviceId().equals("34")).findFirst().orElse(null);//X
						y33 = Double.parseDouble(deviceListDTO33.getAttributeListDTO().get(0).getValue().toString());
						x34 = Double.parseDouble(deviceListDTO34.getAttributeListDTO().get(0).getValue().toString());

						if(nOne3334==null){
							nOne3334 = new AbsolutelyValueTable();
							nOne3334.setBenchTypeCode(3334);
							nOne3334.setY(y33);
							nOne3334.setDipX(x34);
							nOne3334.setMeasurChainDirection(measuringTypeCode);
							iAbsolutelyValueTableService.save(nOne3334);
						}
						y33 =  ((y33 - nOne3334.getY()) / 100 );
						x34 =  (((x34 - nOne3334.getDipX()) / 100 ) * -1);
						}
					}


					return PhysicalQuantityVO.builder().nZ(nz).zX(zx).zZ(zz).nX(nx)
						.deltaY(deltaY)
						.dipY(dipY)
						.dipX(dipX)
						.ccd2AfterDipY(ccd2_after_dip_y)
						.ccd2FrontDipY(ccd2_front_dip_y)
						.ccd1FrontDipX(ccd1_front_dip_x)
						.ccd1AfterDipX(ccd1_after_dip_x)
						.ccd3AfterTangentialY(ccd3_after_tangential_y)
						.ccd3FrontTangentialY(ccd3_front_tangential_y)
						.x26(x26).x28(x28).x29(x29).x32(x32).x33(x34)
						.y25(y25).y27(y27).y30(y30).y31(y31).y34(y33).build();
				}else {//逆向
					if(parentPlatformId==null){
						Integer ccd3_after_tangential_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_after_tangential_y")).findFirst().get().getValue();
						Integer ccd3_front_tangential_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_front_tangential_y")).findFirst().get().getValue();
						log.info("1逆向deltaY值:{}",Arrays.asList(ccd3_after_tangential_y, ccd3_front_tangential_y));
						Double dipX = 0.0;
						Double dipY = 0.0;
						if(one==null){
							one = new AbsolutelyValueTable();
							one.setMeasurChainDirection(measuringTypeCode);
							one.setDeptId(deviceId);
							one.setzX(0.0);
							one.setnX(0.0);
							one.setzZ(0.0);
							one.setnZ(0.0);
							one.setDipY(0.0);
							one.setMeasurChainCode(deptMeasuringInfoId);
							one.setDipX(0.0);

							one.setCcd3AfterTangentialY(ccd3_after_tangential_y);
							one.setCcd3FrontTangentialY(ccd3_front_tangential_y);

							one.setInsertTime(System.currentTimeMillis());
							iAbsolutelyValueTableService.save(one);
						}
						dipY = dipY - one.getDipY();
						dipX = dipX - one.getDipX();

						List<Double> dobleMath1 = getDobleMath2(ccd3_front_tangential_y , ccd3_after_tangential_y ,one.getCcd3FrontTangentialY(),one.getCcd3AfterTangentialY());
						Double deltaY = getModelData2(dobleMath1.get(0), sysParameterList, PhysicalQuantityEnum.DELTAY)
							- getModelData2(dobleMath1.get(1), sysParameterList, PhysicalQuantityEnum.DELTAY);

						return PhysicalQuantityVO.builder().zX(0.0).nZ(0.0).zZ(0.0).zZ(0.0).nX(0.0).deltaY(deltaY).dipX(dipX).dipY(dipY).build();
					}
					Integer ccd1_x_front_backward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_x_front_backward")).findFirst().get().getValue();
					Integer ccd1_x_after_backward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_x_after_backward")).findFirst().get().getValue();
					Integer ccd4_x_after_backward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd4_x_after_backward")).findFirst().get().getValue();
					Integer ccd4_x_front_backward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd4_x_front_backward")).findFirst().get().getValue();
					//Double zx = baseStationAlgorithm.getPhysicalQuantityFormula(ccd1_x_front_backward, ccd1_x_after_backward, ccd4_x_after_backward, ccd4_x_front_backward);
					log.info("1逆向ccd值:{}",Arrays.asList(ccd1_x_front_backward, ccd1_x_after_backward,ccd4_x_after_backward,ccd4_x_front_backward));
					Double zx = getModelData(Arrays.asList(ccd1_x_front_backward, ccd1_x_after_backward,ccd4_x_after_backward,ccd4_x_front_backward), sysParameterList,PhysicalQuantityEnum.ZX);
					log.info("2逆向ccd值:{}",Arrays.asList(ccd1_x_after_backward,ccd4_x_after_backward));
					Double zx2 = getModelData(Arrays.asList(ccd1_x_after_backward,ccd4_x_after_backward), sysParameterList,PhysicalQuantityEnum.ZX);

					log.info("3逆向ccd值:{}",Arrays.asList(ccd1_x_front_backward,ccd4_x_front_backward));
					Double zx3 = getModelData(Arrays.asList(ccd1_x_front_backward,ccd4_x_front_backward), sysParameterList,PhysicalQuantityEnum.ZX);

					Integer ccd2_z_after_backward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_z_after_backward")).findFirst().get().getValue();
					Integer ccd2_z_front_backward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_z_front_backward")).findFirst().get().getValue();
					Integer ccd3_z_after_backward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_z_after_backward")).findFirst().get().getValue();
					Integer ccd3_z_front_backward = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_z_front_backward")).findFirst().get().getValue();
					// Double zz = baseStationAlgorithm.getPhysicalQuantityFormula(ccd2_z_after_backward, ccd2_z_front_backward, ccd3_z_after_backward, ccd3_z_front_backward);
					Double zz = getModelData(Arrays.asList(ccd2_z_after_backward, ccd2_z_front_backward,ccd3_z_after_backward,ccd3_z_front_backward), sysParameterList,PhysicalQuantityEnum.ZZ);;
					Double zz2 = getModelData(Arrays.asList(ccd2_z_after_backward,ccd3_z_after_backward), sysParameterList,PhysicalQuantityEnum.ZZ);
					Double zz3 = getModelData(Arrays.asList(ccd2_z_front_backward,ccd3_z_front_backward), sysParameterList,PhysicalQuantityEnum.ZZ);


					String deviceChannelId = parentPlatformTypeVO.getDeviceChannelId();
					List<DeviceRuningStateDTO.DeviceListDTO.AttributeListDTO> parentDTO = null;
					Optional<DeviceRuningStateDTO.DeviceListDTO> first = deviceList.stream().filter(l -> l.getDeviceId().equals(deviceChannelId)).findFirst();
					if(first.isPresent()){
						parentDTO = first.get().getAttributeListDTO();
					}else {
						//读取默认值
					}
					assert parentDTO != null;
					Integer ccd1_x_after_forward_p = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_x_after_forward")).findFirst().get().getValue();
					Integer ccd1_x_front_forward_p = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_x_front_forward")).findFirst().get().getValue();
					Integer ccd4_x_after_forward_p = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd4_x_after_forward")).findFirst().get().getValue();
					Integer ccd4_x_front_forward_p = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd4_x_front_forward")).findFirst().get().getValue();

					List<SysParameter> parentSysParameterList = iSysParameterService.list(Wrappers.<SysParameter>query().lambda().eq(SysParameter::getMeasuringPlatformId, parentPlatformTypeVO.getId()));
					Double nx = getModelData(Arrays.asList(ccd1_x_after_forward_p,ccd1_x_front_forward_p,ccd4_x_after_forward_p,ccd4_x_front_forward_p), parentSysParameterList,PhysicalQuantityEnum.NX);;
					Double nx2 = getModelData(Arrays.asList(ccd1_x_after_forward_p,ccd4_x_after_forward_p), parentSysParameterList,PhysicalQuantityEnum.NX);;
					Double nx3 = getModelData(Arrays.asList(ccd1_x_front_forward_p,ccd4_x_front_forward_p), parentSysParameterList,PhysicalQuantityEnum.NX);;


					Integer ccd2_z_after_forward_p = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_z_after_forward")).findFirst().get().getValue();
					Integer ccd2_z_front_forward_p = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_z_front_forward")).findFirst().get().getValue();
					Integer ccd3_z_after_forward_p = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_z_after_forward")).findFirst().get().getValue();
					Integer ccd3_z_front_forward_p = parentDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_z_front_forward")).findFirst().get().getValue();

					Double nz = getModelData(Arrays.asList(ccd2_z_after_forward_p,ccd2_z_front_forward_p,ccd3_z_after_forward_p,ccd3_z_front_forward_p), parentSysParameterList,PhysicalQuantityEnum.NZ);;
					Double nz2 = getModelData(Arrays.asList(ccd2_z_after_forward_p,ccd3_z_after_forward_p), parentSysParameterList,PhysicalQuantityEnum.NZ);
					Double nz3 = getModelData(Arrays.asList(ccd2_z_front_forward_p,ccd3_z_front_forward_p), parentSysParameterList,PhysicalQuantityEnum.NZ);


					Integer ccd3_after_tangential_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_after_tangential_y")).findFirst().get().getValue();
					Integer ccd3_front_tangential_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd3_front_tangential_y")).findFirst().get().getValue();


					Integer ccd2_after_dip_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_after_dip_y")).findFirst().get().getValue();
					Integer ccd2_front_dip_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_front_dip_y")).findFirst().get().getValue();


					Integer ccd1_after_dip_x = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_after_dip_x")).findFirst().get().getValue();
					Integer ccd1_front_dip_x = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_front_dip_x")).findFirst().get().getValue();


					if(one==null){
						one = new AbsolutelyValueTable();
						one.setMeasurChainCode(deptMeasuringInfoId);
						one.setMeasurChainDirection(measuringTypeCode);
						one.setDeptId(deviceId);
						one.setzX(zx);
						one.setnX(nx);
						one.setzZ(zz);
						one.setnZ(nz);
						one.setCcd2FrontDipY(ccd2_front_dip_y);
						one.setCcd2AfterDipY(ccd2_after_dip_y);

						one.setCcd1AfterDipX(ccd1_after_dip_x);
						one.setCcd1FrontDipX(ccd1_front_dip_x);

						one.setCcd3AfterTangentialY(ccd3_after_tangential_y);
						one.setCcd3FrontTangentialY(ccd3_front_tangential_y);
						one.setInsertTime(System.currentTimeMillis());
						iAbsolutelyValueTableService.save(one);
						return PhysicalQuantityVO.builder().nZ(0.0).zX(0.0).zZ(0.0).nX(0.0).deltaY(0.0).dipY(0.0).dipX(0.0).build();
					}

					zx = zx - one.getzX();
					zz = zz - one.getzZ();
					nx = nx - one.getnX();
					nz = nz - one.getnZ();
					//zx =  getDobleMath(zx - one.getzX(),zx2 - one.getzX(),zx3 - one.getzX());
					//zz = getDobleMath(zz - one.getzZ(), zz2 - one.getzZ(), zz3 - one.getzZ());
					//nx = getDobleMath(nx - one.getnX(), nx2 - one.getnX(), nx3 - one.getnX());
					//nz = getDobleMath(nz - one.getnZ(), nz2 - one.getnZ(), nz3 - one.getnZ());

					List<Double> dobleMath1 = getDobleMath2(ccd3_front_tangential_y , ccd3_after_tangential_y ,one.getCcd3FrontTangentialY(),one.getCcd3AfterTangentialY());
					Double deltaY = getModelData2(dobleMath1.get(0), sysParameterList, PhysicalQuantityEnum.DELTAY)
						- getModelData2(dobleMath1.get(1), sysParameterList, PhysicalQuantityEnum.DELTAY);


					double dipX;
					if(ccd2_after_dip_y>7000||(ccd2_after_dip_y<=500&&ccd2_after_dip_y>0)&&(ccd2_front_dip_y<7000&&ccd2_front_dip_y>500)){//异常点
						dipX = getModelData2(Double.valueOf(ccd2_front_dip_y), sysParameterList, PhysicalQuantityEnum.DIPY)
							- getModelData2(Double.valueOf(one.getCcd2FrontDipY()), sysParameterList, PhysicalQuantityEnum.DIPY);
					}else if(ccd2_front_dip_y>7000||(ccd2_front_dip_y<=500&&ccd2_front_dip_y>0)&&(ccd2_after_dip_y<7000&&ccd2_after_dip_y>500)){
						dipX = getModelData2(Double.valueOf(ccd2_after_dip_y), sysParameterList, PhysicalQuantityEnum.DIPY)
							- getModelData2(Double.valueOf(one.getCcd2AfterDipY()), sysParameterList, PhysicalQuantityEnum.DIPY);
					}else {
						List<Double> dobleMath2 = getDobleMath2(ccd2_after_dip_y , ccd2_front_dip_y,one.getCcd2AfterDipY(),one.getCcd2FrontDipY());
						dipX = getModelData2(dobleMath2.get(0), sysParameterList, PhysicalQuantityEnum.DIPY)
							- getModelData2(dobleMath2.get(1), sysParameterList, PhysicalQuantityEnum.DIPY);
					}
					List<Double> dobleMath3 = getDobleMath2(ccd1_front_dip_x , ccd1_after_dip_x,one.getCcd1FrontDipX() ,one.getCcd1AfterDipX());
					Double dipY = getModelData2(dobleMath3.get(0), sysParameterList,PhysicalQuantityEnum.DIPX)
						- getModelData2(dobleMath3.get(1), sysParameterList, PhysicalQuantityEnum.DIPX);
					Double x26 = null;
					Double y25 = null;
					Double x28= null;
					Double y27= null;
					Double x29= null;
					Double y30= null;
					Double x32= null;
					Double y31= null;
					Double x34= null;
					Double y33= null;
				MeasuringPlatformType byId = iMeasuringPlatformTypeService.getById(measuringPlatformId);
					if(Func.isNotEmpty(byId.getCoordinatChannelId())){
						if(byId.getCoordinatChannelId().contains("25")){
							AbsolutelyValueTable one1 = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
							.eq(AbsolutelyValueTable::getMeasurChainDirection, measuringTypeCode).eq(AbsolutelyValueTable::getBenchTypeCode, 2526));//正
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO3 = deviceList.stream().filter(l -> l.getDeviceId().equals("26")).findFirst().orElse(null);
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO4 = deviceList.stream().filter(l -> l.getDeviceId().equals("25")).findFirst().orElse(null);
						x26 = Double.parseDouble(deviceListDTO3.getAttributeListDTO().get(0).getValue().toString());
						y25 = Double.parseDouble(deviceListDTO4.getAttributeListDTO().get(0).getValue().toString());


						if(one1==null){
							one1 = new AbsolutelyValueTable();
							one1.setBenchTypeCode(2526);
							one1.setY(y25);
							one1.setDipX(x26);
							one1.setMeasurChainDirection(measuringTypeCode);
							iAbsolutelyValueTableService.save(one1);
						}
						x26 = (((x26 - one1.getDipX()) / 100 )  * -1);
						y25 = ((y25 - one1.getY()) / 100 );


						AbsolutelyValueTable nOne = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
							.eq(AbsolutelyValueTable::getMeasurChainDirection, measuringTypeCode).eq(AbsolutelyValueTable::getBenchTypeCode, 2728));//dao
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO27 = deviceList.stream().filter(l -> l.getDeviceId().equals("28")).findFirst().orElse(null);
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO28 = deviceList.stream().filter(l -> l.getDeviceId().equals("27")).findFirst().orElse(null);
						double x2728 = Double.parseDouble(deviceListDTO27.getAttributeListDTO().get(0).getValue().toString());
						double y2728 = Double.parseDouble(deviceListDTO28.getAttributeListDTO().get(0).getValue().toString());

						if(nOne==null){
							nOne = new AbsolutelyValueTable();
							nOne.setBenchTypeCode(2728);
							nOne.setY(y2728);
							nOne.setDipX(x2728);
							nOne.setMeasurChainDirection(measuringTypeCode);
							iAbsolutelyValueTableService.save(nOne);
						}
						x28 =  (((x2728 - nOne.getDipX()) / 100 )* -1);
						y27 =  (((y2728 - nOne.getY()) / 100 )* -1);


						AbsolutelyValueTable nOne29 = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
							.eq(AbsolutelyValueTable::getMeasurChainDirection, measuringTypeCode).eq(AbsolutelyValueTable::getBenchTypeCode, 2930));//dao
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO29 = deviceList.stream().filter(l -> l.getDeviceId().equals("29")).findFirst().orElse(null);
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO30 = deviceList.stream().filter(l -> l.getDeviceId().equals("30")).findFirst().orElse(null);
						x29 = Double.parseDouble(deviceListDTO29.getAttributeListDTO().get(0).getValue().toString());
						y30 = Double.parseDouble(deviceListDTO30.getAttributeListDTO().get(0).getValue().toString());


						if(nOne29==null){
							nOne29 = new AbsolutelyValueTable();
							nOne29.setBenchTypeCode(2930);
							nOne29.setY(y30);
							nOne29.setDipX(x29);
							nOne29.setMeasurChainDirection(measuringTypeCode);
							iAbsolutelyValueTableService.save(nOne29);
						}
						x29 =  (((x29 - nOne29.getDipX()) / 100 ) * -1);
						y30 =  (((y30 - nOne29.getY()) / 100 )* -1);


						AbsolutelyValueTable nOne3132 = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
							.eq(AbsolutelyValueTable::getMeasurChainDirection, measuringTypeCode).eq(AbsolutelyValueTable::getBenchTypeCode, 3132));//dao
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO32 = deviceList.stream().filter(l -> l.getDeviceId().equals("32")).findFirst().orElse(null);
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO31 = deviceList.stream().filter(l -> l.getDeviceId().equals("31")).findFirst().orElse(null);
						x32 = Double.parseDouble(deviceListDTO32.getAttributeListDTO().get(0).getValue().toString());
						y31 = Double.parseDouble(deviceListDTO31.getAttributeListDTO().get(0).getValue().toString());

						if(nOne3132==null){
							nOne3132 = new AbsolutelyValueTable();
							nOne3132.setBenchTypeCode(3132);
							nOne3132.setY(y31);
							nOne3132.setDipX(x32);
							nOne3132.setMeasurChainDirection(measuringTypeCode);
							iAbsolutelyValueTableService.save(nOne3132);
						}
						x32 =  (((x32 - nOne3132.getDipX()) / 100 ) * -1);
						y31 =  ((y31 - nOne3132.getY()) / 100 );


						AbsolutelyValueTable nOne3334 = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
							.eq(AbsolutelyValueTable::getMeasurChainDirection, measuringTypeCode).eq(AbsolutelyValueTable::getBenchTypeCode, 3334));//dao
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO33 = deviceList.stream().filter(l -> l.getDeviceId().equals("33")).findFirst().orElse(null);//Y
						DeviceRuningStateDTO.DeviceListDTO deviceListDTO34 = deviceList.stream().filter(l -> l.getDeviceId().equals("34")).findFirst().orElse(null);//X
						y33 = Double.parseDouble(deviceListDTO33.getAttributeListDTO().get(0).getValue().toString());
						x34 = Double.parseDouble(deviceListDTO34.getAttributeListDTO().get(0).getValue().toString());

						if(nOne3334==null){
							nOne3334 = new AbsolutelyValueTable();
							nOne3334.setBenchTypeCode(3334);
							nOne3334.setY(y33);
							nOne3334.setDipX(x34);
							nOne3334.setMeasurChainDirection(measuringTypeCode);
							iAbsolutelyValueTableService.save(nOne3334);
						}
						y33 =  ((y33 - nOne3334.getY()) / 100 );
						x34 =  (((x34 - nOne3334.getDipX()) / 100 ) * -1);
						}
					}




					return PhysicalQuantityVO.builder()
						.nZ(nz)
						.zX(zx)
						.zZ(zz)
						.nX(nx)
						.deltaY(deltaY)
						.dipY(dipY)
						.dipX(dipX)
						.ccd2AfterDipY(ccd2_after_dip_y)
						.ccd2FrontDipY(ccd2_front_dip_y)
						.ccd1FrontDipX(ccd1_front_dip_x)
						.ccd1AfterDipX(ccd1_after_dip_x)
						.ccd3AfterTangentialY(ccd3_after_tangential_y)
						.ccd3FrontTangentialY(ccd3_front_tangential_y).x26(x26).x28(x28).x29(x29).x32(x32).x33(x34)
						.y25(y25).y27(y27).y30(y30).y31(y31).y34(y33).build();
				}
			}

		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;


	}
	/**
	 * 基点测台计算工程量
	 * @param measuringPlatformConfigVO
	 * @param deviceList
	 * @return
	 */
	private AbsoluteValueVO getAbsoluteValue( List<String> lists,
											  Map<String,DeviceTableVO> mapd ,
											  MeasuringPlatformConfigVO measuringPlatformConfigVO,
											  List<DeviceRuningStateDTO.DeviceListDTO> deviceList,
											  Long id,
											  Long acquisitionTime){
		try {
			double x = 0.0;
			double y = 0.0;
			Double z = null;
			Double alpha = null;
			Double beta = null;
			Double gama = null;

			List<DeviceRuningStateDTO.DeviceListDTO> collect = deviceList.stream().filter(l -> lists.contains(l.getDeviceId())).collect(Collectors.toList());
			List<SysParameter> sysParameterList = iSysParameterService.list(Wrappers.<SysParameter>query().lambda().eq(SysParameter::getMeasuringPlatformId,id));
			for (DeviceRuningStateDTO.DeviceListDTO deviceListDTO : collect) {
				// DeviceTable deviceTableVO = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda().eq(DeviceTable::getDeviceChannelId, deviceListDTO.getDeviceId()).eq(DeviceTable::getIsDeleted, 0));
				DeviceTableVO deviceTableVO = mapd.get(deviceListDTO.getDeviceId());

				List<DeviceRuningStateDTO.DeviceListDTO.AttributeListDTO> attributeListDTO = deviceListDTO.getAttributeListDTO();
				switch (Objects.requireNonNull(ProductTypeEnum.getEnum(deviceTableVO.getProductId()))){
					case HT_GONIOMETER://华腾绕角仪
						Integer ccd3_z_front = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd3_z_front")).findFirst().get().getValue();
						Integer ccd3_z_after = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd3_z_after")).findFirst().get().getValue();
						gama = getModelData(Arrays.asList(ccd3_z_front, ccd3_z_after), sysParameterList,PhysicalQuantityEnum.GAMA);
						//gama = baseStationAlgorithm.getPhysicalQuantityDip(Double.valueOf(rich_z_K), ccd3_z_after, ccd3_z_front, Double.valueOf(rich_z_B));
						//绕Z轴的旋转角
						break;
					case HT_DOUBLE_MARKER://华腾双标仪
						Integer ccd3_z_front1 = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd3_z_front")).findFirst().get().getValue();
						Integer ccd3_z_after1 = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd3_z_after")).findFirst().get().getValue();
						// z  = baseStationAlgorithm.getDeformation(ccd3_z_after1,ccd3_z_front1);
						z = getModelData(Arrays.asList(ccd3_z_front1, ccd3_z_after1), sysParameterList,PhysicalQuantityEnum.Z);
						break;
					case HT_PERPENDICULOMETER://华腾垂线仪
						Integer ccd3_x_front = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd3_x_front")).findFirst().get().getValue();
						Integer ccd3_x_after = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd3_x_after")).findFirst().get().getValue();
						alpha = getModelData(Arrays.asList(ccd3_x_front, ccd3_x_after), sysParameterList,PhysicalQuantityEnum.ALPHA);
						//alpha  = baseStationAlgorithm.getPhysicalQuantityDip(Double.valueOf(rich_x_K), ccd3_x_after, ccd3_x_front, Double.valueOf(rich_x_B));

						Integer ccd1_y_front = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd1_y_front")).findFirst().get().getValue();
						Integer ccd1_y_after = attributeListDTO.stream().filter(l -> l.getKey().equalsIgnoreCase("ccd1_y_after")).findFirst().get().getValue();
						beta = getModelData(Arrays.asList(ccd1_y_front, ccd1_y_after), sysParameterList,PhysicalQuantityEnum.BETA);
						//beta  = baseStationAlgorithm.getPhysicalQuantityDip(Double.valueOf(rich_y_K), ccd1_y_after, ccd1_y_front, Double.valueOf(rich_y_B));
						break;
				}
			}
			List<String> strings = new ArrayList<>();
			if(measuringPlatformConfigVO!=null){//走配置的策略

				Integer xType = measuringPlatformConfigVO.getxType();
				if(xType!=null){
					if(xType.equals(DataStrategyEnum.MANUAL.getCode())){
						x = Double.parseDouble(measuringPlatformConfigVO.getxValue());
					}else {
						//未给出结算规则
					}

				}
				Integer yType = measuringPlatformConfigVO.getyType();
				if(yType!=null){
					if(yType.equals(DataStrategyEnum.MANUAL.getCode())){
						y = Double.parseDouble(measuringPlatformConfigVO.getyValue());
					}else {
						//未给出结算规则
					}
				}
				Integer zType = measuringPlatformConfigVO.getzType();
				if(zType!=null){
					if(zType.equals(DataStrategyEnum.MANUAL.getCode())){
						z = Double.parseDouble(measuringPlatformConfigVO.getzValue());
					}else {
						//未给出结算规则
					}
				}
				Map<String, Double> dataStrategy;
				Integer alphaType = measuringPlatformConfigVO.getAlphaType();
				if(alphaType!=null){
					if(alphaType.equals(DataStrategyEnum.MANUAL.getCode())){
						alpha = Double.parseDouble(measuringPlatformConfigVO.getAlphaValue());
					}else if(alphaType.equals(DataStrategyEnum.COMPANY.getCode())){
						dataStrategy =  getDataStrategy(id,measuringPlatformConfigVO.getAlphaValue(),measuringPlatformConfigVO.getPlatformTypeCode(),deviceList);//ccd1AfterDipx1
						alpha = dataStrategy.get("dipX");
						strings.add(measuringPlatformConfigVO.getAlphaValue());
					}
				}
				Integer betaType = measuringPlatformConfigVO.getBetaType();
				if(betaType!=null){
					if(betaType.equals(DataStrategyEnum.MANUAL.getCode())){
						beta = Double.parseDouble(measuringPlatformConfigVO.getBetaValue());
					}else if(betaType.equals(DataStrategyEnum.COMPANY.getCode())){
						dataStrategy = getDataStrategy(id,measuringPlatformConfigVO.getBetaValue(), measuringPlatformConfigVO.getPlatformTypeCode(), deviceList);
						beta = dataStrategy.get("dipY");
						strings.add(measuringPlatformConfigVO.getBetaValue());
					}
				}
				Integer gamaType = measuringPlatformConfigVO.getGamaType();
				if(gamaType!=null){
					if(gamaType.equals(DataStrategyEnum.MANUAL.getCode())){
						gama = Double.parseDouble(measuringPlatformConfigVO.getGamaValue());
					}else if(gamaType.equals(DataStrategyEnum.COMPANY.getCode())){
						//没有提供算法
					}
				}
			}

			return AbsoluteValueVO.builder().x(x).y(y).z(z).alpha(alpha).beta(beta).gama(gama).stringList(strings).build();

		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;

	}

	private Map<String,Double> getDataStrategy(Long measuringPlatformId,String value, Integer platformTypeCode, List<DeviceRuningStateDTO.DeviceListDTO> deviceList){
		try {

			Map<String,Double> map = new HashMap<>();
			List<DeviceRuningStateDTO.DeviceListDTO.AttributeListDTO> attributeListDTO;
			DeviceTable deviceTableVO = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda().eq(DeviceTable::getDeviceId,value).eq(DeviceTable::getIsDeleted, 0));
			Optional<DeviceRuningStateDTO.DeviceListDTO> first = deviceList.stream().filter(x -> x.getDeviceId().equals( deviceTableVO.getDeviceChannelId())).findFirst();
			if(first.isPresent()){
				DeviceRuningStateDTO.DeviceListDTO deviceListDTO = first.get();
				attributeListDTO = deviceListDTO.getAttributeListDTO();
			}else {
				//查询默认值
				attributeListDTO = new ArrayList<>();
			}
			//高精度传感器一次量


			Integer ccd2_after_dip_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_after_dip_y")).findFirst().get().getValue();
			Integer ccd2_front_dip_y = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd2_front_dip_y")).findFirst().get().getValue();

			Integer ccd1_after_dip_x = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_after_dip_x")).findFirst().get().getValue();
			Integer ccd1_front_dip_x = attributeListDTO.stream().filter(x -> x.getKey().equalsIgnoreCase("ccd1_front_dip_x")).findFirst().get().getValue();


			AbsolutelyValueTable one = iAbsolutelyValueTableService.getOne(Wrappers.<AbsolutelyValueTable>lambdaQuery()
				.eq(AbsolutelyValueTable::getDeptId,value).eq(AbsolutelyValueTable::getMeasurChainDirection,platformTypeCode));

			List<SysParameter> sysParameterList = iSysParameterService.list(Wrappers.<SysParameter>query().lambda().eq(SysParameter::getMeasuringPlatformId,measuringPlatformId));
			if(one==null){
/*			Double v3 =  getModelData(Arrays.asList(ccd2_after_dip_y,ccd2_front_dip_y),sysParameterList,PhysicalQuantityEnum.DIPY);
			Double v2 =  getModelData(Arrays.asList(ccd1_after_dip_x,ccd1_front_dip_x),sysParameterList,PhysicalQuantityEnum.DIPX);*/
				one = new AbsolutelyValueTable();
				one.setMeasurChainDirection(platformTypeCode);
				one.setDeptId(value);
				one.setCcd2FrontDipY(ccd2_front_dip_y);
				one.setCcd2AfterDipY(ccd2_after_dip_y);

				one.setCcd1AfterDipX(ccd1_after_dip_x);
				one.setCcd1FrontDipX(ccd1_front_dip_x);
   /*         one.setDipX(v3);
            one.setDipY(v2);*/
				iAbsolutelyValueTableService.save(one);

				map.put("dipX",0.0);
				map.put("dipY",0.0);
				return map;
			}else {
				double dipX;
				if(ccd2_after_dip_y>7000||(ccd2_after_dip_y<=500&&ccd2_after_dip_y>0)&&(ccd2_front_dip_y<7000&&ccd2_front_dip_y>500)){//异常点
					dipX = getModelData2(Double.valueOf(ccd2_front_dip_y), sysParameterList, PhysicalQuantityEnum.DIPY)
						- getModelData2(Double.valueOf(one.getCcd2FrontDipY()), sysParameterList, PhysicalQuantityEnum.DIPY);
				}else if(ccd2_front_dip_y>7000||(ccd2_front_dip_y<=500&&ccd2_front_dip_y>0)&&(ccd2_after_dip_y<7000&&ccd2_after_dip_y>500)){
					dipX = getModelData2(Double.valueOf(ccd2_after_dip_y), sysParameterList, PhysicalQuantityEnum.DIPY)
						- getModelData2(Double.valueOf(one.getCcd2AfterDipY()), sysParameterList, PhysicalQuantityEnum.DIPY);
				}else {
					List<Double> dobleMath2 = getDobleMath2(ccd2_after_dip_y , ccd2_front_dip_y,one.getCcd2AfterDipY(),one.getCcd2FrontDipY());
					dipX = getModelData2(dobleMath2.get(0), sysParameterList, PhysicalQuantityEnum.DIPY)
						- getModelData2(dobleMath2.get(1), sysParameterList, PhysicalQuantityEnum.DIPY);
				}



				List<Double> dobleMath3 = getDobleMath2(ccd1_front_dip_x , ccd1_after_dip_x,one.getCcd1FrontDipX() ,one.getCcd1AfterDipX());
				Double v = getModelData2(dobleMath3.get(0), sysParameterList,PhysicalQuantityEnum.DIPX)
					- getModelData2(dobleMath3.get(1), sysParameterList, PhysicalQuantityEnum.DIPX);

/*            Double v =  getModelData(Arrays.asList(ccd1_after_dip_x ,ccd1_front_dip_x ),sysParameterList,PhysicalQuantityEnum.DIPX);
            Double v1 =  getModelData(Arrays.asList(ccd2_after_dip_y ,ccd2_front_dip_y ),sysParameterList,PhysicalQuantityEnum.DIPY);*/
				map.put("dipX",dipX);
				map.put("dipY",v);
				log.info("高精度传感器计算map:{}",map);
				return map;
			}
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;






	}
	@Autowired
	EngineerValueRepairTableMapper engineerValueRepairTableMapper;
	private void saveMeasuringChainDetails(MeasuringChainDetailsVO measuringChainDetailsVO,String acquisitionFlag) {
		try {

			List<MeasuringPlatformVO> measuringPlatformVOS = measuringChainDetailsVO.getMeasuringPlatformVOS();
			if (!Func.isEmpty(measuringPlatformVOS)) {

				List<MeasuringPlatformVO> collect = measuringPlatformVOS.stream().sorted(Comparator.comparing(MeasuringPlatformVO::getSort).reversed()).collect(Collectors.toList());
				log.info("入库开始:{}",collect);
				List<PhysicalValueTable> physicalValueTables = collect.stream().map(measuringPlatformVO -> {
					PhysicalValueTable physicalValueTable = new PhysicalValueTable();
					physicalValueTable.setGatherEvent(measuringChainDetailsVO.getGatherEvent());
					physicalValueTable.setGatherTime(measuringChainDetailsVO.getGatherTime());
					physicalValueTable.setMeasurChainCode(measuringChainDetailsVO.getMeasurChainCode());
					physicalValueTable.setMeasurChain(measuringChainDetailsVO.getMeasurChain());
					physicalValueTable.setMeasurChainDirection(measuringChainDetailsVO.getMeasurChainDirection());
					physicalValueTable.setMeasurChainDirectionName(measuringChainDetailsVO.getMeasurChainDirection() == 1 ? "正向" : "逆向");
					physicalValueTable.setInsertTime(System.currentTimeMillis());
					physicalValueTable.setBenchTypeCode(measuringPlatformVO.getBenchTypeCode());
					physicalValueTable.setBenchTypeName(measuringPlatformVO.getBenchTypeName());
					physicalValueTable.setDeptId(measuringPlatformVO.getMeasuringPlatformId());
					physicalValueTable.setDeptName(measuringPlatformVO.getMeasuringPlatformName());
					PhysicalQuantityVO physicalQuantityVO = measuringPlatformVO.getPhysicalQuantityVO();
					BigDecimal nx = new BigDecimal(physicalQuantityVO.getNX()).setScale(10, RoundingMode.DOWN);
					physicalValueTable.setnX(nx.doubleValue());
					BigDecimal nz = new BigDecimal(physicalQuantityVO.getNZ()).setScale(10, RoundingMode.DOWN);
					physicalValueTable.setnZ(nz.doubleValue());
					BigDecimal zz = new BigDecimal(physicalQuantityVO.getZZ()).setScale(10, RoundingMode.DOWN);
					physicalValueTable.setzZ(zz.doubleValue());
					BigDecimal zx = new BigDecimal(physicalQuantityVO.getZX()).setScale(10, RoundingMode.DOWN);
					physicalValueTable.setzX(zx.doubleValue());
					BigDecimal deltaY = new BigDecimal(physicalQuantityVO.getDeltaY()).setScale(10, RoundingMode.DOWN);
					physicalValueTable.setDeltaY(deltaY.doubleValue());
					BigDecimal dipy = new BigDecimal(physicalQuantityVO.getDipY()).setScale(10, RoundingMode.DOWN);
					physicalValueTable.setDipY(dipy.doubleValue());
					BigDecimal dipx = new BigDecimal(physicalQuantityVO.getDipX()).setScale(10, RoundingMode.DOWN);
					physicalValueTable.setDipX(dipx.doubleValue());
					physicalValueTable.setAcquisitionFlag(acquisitionFlag);
					physicalValueTable.setY(physicalQuantityVO.getY());
					physicalValueTable.setCcd3AfterTangentialY(physicalQuantityVO.getCcd3AfterTangentialY());
					physicalValueTable.setCcd3FrontTangentialY(physicalQuantityVO.getCcd3FrontTangentialY());
					physicalValueTable.setCcd2AfterDipY(physicalQuantityVO.getCcd2AfterDipY());
					physicalValueTable.setCcd2FrontDipY(physicalQuantityVO.getCcd2FrontDipY());
					physicalValueTable.setCcd1AfterDipX(physicalQuantityVO.getCcd1AfterDipX());
					physicalValueTable.setCcd1FrontDipX(physicalQuantityVO.getCcd1FrontDipX());
					physicalValueTable.setX26(physicalQuantityVO.getX26());
					physicalValueTable.setX28(physicalQuantityVO.getX28());
					physicalValueTable.setX29(physicalQuantityVO.getX29());
					physicalValueTable.setX32(physicalQuantityVO.getX32());
					physicalValueTable.setX33(physicalQuantityVO.getX33());
					physicalValueTable.setY25(physicalQuantityVO.getY25());
					physicalValueTable.setY27(physicalQuantityVO.getY27());
					physicalValueTable.setY30(physicalQuantityVO.getY30());
					physicalValueTable.setY31(physicalQuantityVO.getY31());
					physicalValueTable.setY34(physicalQuantityVO.getY34());

					return physicalValueTable;
				}).collect(Collectors.toList());

				iPhysicalValueTableService.saveBatch(physicalValueTables);


				List<EngineerValueTable> engineerValueTables = collect.stream().map(measuringPlatformVO -> {
					AbsoluteValueVO absoluteValueVO = measuringPlatformVO.getAbsoluteValueVO();
					EngineerValueTable engineerValueTable = new EngineerValueTable();
					engineerValueTable.setGatherEvent(measuringChainDetailsVO.getGatherEvent());
					engineerValueTable.setGatherTime(measuringChainDetailsVO.getGatherTime());
					engineerValueTable.setMeasurChainCode(measuringChainDetailsVO.getMeasurChainCode());
					engineerValueTable.setMeasurChain(measuringChainDetailsVO.getMeasurChain());
					engineerValueTable.setMeasurChainDirection(measuringChainDetailsVO.getMeasurChainDirection());
					engineerValueTable.setMeasurChainDirectionName(measuringChainDetailsVO.getMeasurChainDirection() == 1 ? "正向" : "逆向");
					engineerValueTable.setInsertTime(System.currentTimeMillis());
					engineerValueTable.setBenchTypeCode(measuringPlatformVO.getBenchTypeCode());
					engineerValueTable.setBenchTypeName(measuringPlatformVO.getBenchTypeName());
					engineerValueTable.setDeptId(measuringPlatformVO.getMeasuringPlatformId());
					engineerValueTable.setDeptName(measuringPlatformVO.getMeasuringPlatformName());
					List<EngineerValueRepairTable> engineerValueRepairTables = engineerValueRepairTableMapper.selectList(Wrappers.lambdaQuery());
					if(Func.isNotEmpty(engineerValueRepairTables)){
						EngineerValueRepairTable engineerValueRepairTable = engineerValueRepairTables.stream().filter(x -> Objects.equals(x.getDeptId(), measuringPlatformVO.getMeasuringPlatformId()) && Objects.equals(x.getMeasurChainDirection(), measuringChainDetailsVO.getMeasurChainDirection())).findFirst().orElse(null);

						if(engineerValueRepairTable!=null){
							BigDecimal x = new BigDecimal(absoluteValueVO.getX()).setScale(10, RoundingMode.DOWN);
							engineerValueTable.setX(x.doubleValue()+engineerValueRepairTable.getX());

							BigDecimal y = new BigDecimal(absoluteValueVO.getY()).setScale(10, RoundingMode.DOWN);
							engineerValueTable.setY(y.doubleValue()+engineerValueRepairTable.getY());

							BigDecimal z = new BigDecimal(absoluteValueVO.getZ()).setScale(10, RoundingMode.DOWN);
							engineerValueTable.setZ(z.doubleValue()+engineerValueRepairTable.getZ());
						}else {
							BigDecimal x = new BigDecimal(absoluteValueVO.getX()).setScale(10, RoundingMode.DOWN);
							engineerValueTable.setX(x.doubleValue());

							BigDecimal y = new BigDecimal(absoluteValueVO.getY()).setScale(10, RoundingMode.DOWN);
							engineerValueTable.setY(y.doubleValue());

							BigDecimal z = new BigDecimal(absoluteValueVO.getZ()).setScale(10, RoundingMode.DOWN);
							engineerValueTable.setZ(z.doubleValue());
						}
					}else {
						BigDecimal x = new BigDecimal(absoluteValueVO.getX()).setScale(10, RoundingMode.DOWN);
						engineerValueTable.setX(x.doubleValue());

						BigDecimal y = new BigDecimal(absoluteValueVO.getY()).setScale(10, RoundingMode.DOWN);
						engineerValueTable.setY(y.doubleValue());

						BigDecimal z = new BigDecimal(absoluteValueVO.getZ()).setScale(10, RoundingMode.DOWN);
						engineerValueTable.setZ(z.doubleValue());
					}
					BigDecimal alpha = new BigDecimal(absoluteValueVO.getAlpha()).setScale(10, RoundingMode.DOWN);
					engineerValueTable.setAlpha(alpha.doubleValue());

					BigDecimal bate = new BigDecimal(absoluteValueVO.getBeta()).setScale(10, RoundingMode.DOWN);
					engineerValueTable.setBeta(bate.doubleValue());

					BigDecimal gama = new BigDecimal(absoluteValueVO.getGama()).setScale(10, RoundingMode.DOWN);
					engineerValueTable.setGama(gama.doubleValue());


					engineerValueTable.setAcquisitionFlag(acquisitionFlag);
					return engineerValueTable;

				}).collect(Collectors.toList());
				log.info("计算工程量为:{}",engineerValueTables);

				iEngineerValueTableService.saveBatch(engineerValueTables);

				collect.forEach(measuringPlatformVO->{
					List<OnceValueVO> onceValueVOList = measuringPlatformVO.getOnceValueVOList();
					if(!Func.isEmpty(onceValueVOList)){
						for (OnceValueVO l1 : onceValueVOList) {

							List<MeasuringPointTable> list = iMeasuringPointTableService.list(Wrappers.<MeasuringPointTable>lambdaQuery()
								.eq(MeasuringPointTable::getGatherTime, measuringChainDetailsVO.getGatherTime())
								.eq(MeasuringPointTable::getMeasurChainCode, measuringChainDetailsVO.getMeasurChainCode())
								.eq(MeasuringPointTable::getMeasurChainDirection, measuringChainDetailsVO.getMeasurChainDirection())
								.eq(MeasuringPointTable::getDeviceId, l1.getDeviceId())
								.eq(MeasuringPointTable::getPropertieId, l1.getPropertieId()));
							if(CollectionUtil.isEmpty(list)){
								MeasuringPointTable measuringPointTable = new MeasuringPointTable();
								measuringPointTable.setGatherTime(measuringChainDetailsVO.getGatherTime());
								measuringPointTable.setGatherEvent(measuringChainDetailsVO.getGatherEvent());
								measuringPointTable.setMeasurChainCode(measuringChainDetailsVO.getMeasurChainCode());
								measuringPointTable.setMeasurChain(measuringChainDetailsVO.getMeasurChain());
								measuringPointTable.setMeasurChainDirection(measuringChainDetailsVO.getMeasurChainDirection());
								measuringPointTable.setMeasurChainDirectionName(measuringChainDetailsVO.getMeasurChainDirection() == 1 ? "正向" : "逆向");
								measuringPointTable.setInsertTime(System.currentTimeMillis());
								measuringPointTable.setBenchTypeCode(measuringPlatformVO.getBenchTypeCode());
								measuringPointTable.setBenchTypeName(measuringPlatformVO.getBenchTypeName());
								measuringPointTable.setDeptId(measuringPlatformVO.getMeasuringPlatformId());
								measuringPointTable.setDeptName(measuringPlatformVO.getMeasuringPlatformName());
								measuringPointTable.setDeviceId(l1.getDeviceId());
								measuringPointTable.setDeviceName(l1.getDeviceName());
								measuringPointTable.setPropertieId(l1.getPropertieId());
								measuringPointTable.setPropertieName(l1.getPropertieName());
								measuringPointTable.setOnceValue(Integer.parseInt(l1.getOnceValue()));
								measuringPointTable.setInsertTime(System.currentTimeMillis());
								measuringPointTable.setRietschlePressure(measuringChainDetailsVO.getRietschlePressure());
								measuringPointTable.setAcquisitionFlag(acquisitionFlag);
								iMeasuringPointTableService.save(measuringPointTable);
							}


						}
					}
				});

			}
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}


	}
	private List<OnceValueVO> getOnceValue(DeviceRuningStateDTO.DeviceListDTO deviceListDTO,Long gatherTime,String deviceId,
										   String acquisitionFlag,String coordinatChannelId,  List<DeviceRuningStateDTO.DeviceListDTO> deviceList){
		try {

			List<OnceValueVO> onceValueVOList = new ArrayList<>();
			DeviceTable deviceTableVO = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda().eq(DeviceTable::getDeviceId,deviceId).eq(DeviceTable::getIsDeleted, 0));
			if(Func.isNotEmpty(coordinatChannelId)){
				if(coordinatChannelId.equalsIgnoreCase("1")){//获取正向1号侧台的X

					DeviceTable deviceTableVO1 = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda().eq(DeviceTable::getDeviceChannelId,coordinatChannelId).eq(DeviceTable::getIsDeleted, 0));

					onceValueVOList.add( OnceValueVO.builder().onceValue("0")
						.deviceName(deviceTableVO1.getDeviceName())
						.deviceId(deviceTableVO1.getDeviceId())
						.deviceChannelId(deviceTableVO1.getDeviceChannelId()).propertieId("temperature").propertieName("温度").build());
					onceValueVOList.add( OnceValueVO.builder().onceValue("0")
						.deviceName(deviceTableVO1.getDeviceName())
						.deviceId(deviceTableVO1.getDeviceId())
						.deviceChannelId(deviceTableVO.getDeviceChannelId()).propertieId("electricity").propertieName("电流").build());

					onceValueVOList.add( OnceValueVO.builder().onceValue("0")
						.deviceName(deviceTableVO1.getDeviceName())
						.deviceId(deviceTableVO1.getDeviceId())
						.deviceChannelId(deviceTableVO1.getDeviceChannelId()).propertieId("ccd3_x_front").propertieName("CCD3-脉冲前沿-X向位移").build());
					onceValueVOList.add( OnceValueVO.builder().onceValue("0")
						.deviceName(deviceTableVO1.getDeviceName())
						.deviceId(deviceTableVO1.getDeviceId())
						.deviceChannelId(deviceTableVO1.getDeviceChannelId()).propertieId("ccd3_x_after").propertieName("CCD3-脉冲后沿-X向位移").build());

					onceValueVOList.add( OnceValueVO.builder().onceValue("0")
						.deviceName(deviceTableVO1.getDeviceName())
						.deviceId(deviceTableVO1.getDeviceId())
						.deviceChannelId(deviceTableVO1.getDeviceChannelId()).propertieId("ccd1_y_front").propertieName("CCD1-脉冲前沿-Y向位移").build());

					onceValueVOList.add( OnceValueVO.builder().onceValue("0")
						.deviceName(deviceTableVO1.getDeviceName())
						.deviceId(deviceTableVO1.getDeviceId())
						.deviceChannelId(deviceTableVO1.getDeviceChannelId()).propertieId("ccd1_y_after").propertieName("CCD1-脉冲后沿-Y向位移").build());
				}else if(coordinatChannelId.equalsIgnoreCase("22")){//获取正向18号侧台的X
					DeviceTable deviceTableVO1 = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda()
						.eq(DeviceTable::getDeviceChannelId,coordinatChannelId).eq(DeviceTable::getIsDeleted, 0));


					onceValueVOList.add( OnceValueVO.builder().onceValue("0")
						.deviceName(deviceTableVO1.getDeviceName())
						.deviceId(deviceTableVO1.getDeviceId())
						.deviceChannelId(deviceTableVO1.getDeviceChannelId()).propertieId("temperature").propertieName("温度").build());
					onceValueVOList.add( OnceValueVO.builder().onceValue("0")
						.deviceName(deviceTableVO1.getDeviceName())
						.deviceId(deviceTableVO1.getDeviceId())
						.deviceChannelId(deviceTableVO1.getDeviceChannelId()).propertieId("electricity").propertieName("电流").build());

					onceValueVOList.add( OnceValueVO.builder().onceValue("0")
						.deviceName(deviceTableVO1.getDeviceName())
						.deviceId(deviceTableVO1.getDeviceId())
						.deviceChannelId(deviceTableVO1.getDeviceChannelId()).propertieId("ccd3_x_front").propertieName("CCD3-脉冲前沿-X向位移").build());
					onceValueVOList.add( OnceValueVO.builder().onceValue("0")
						.deviceName(deviceTableVO1.getDeviceName())
						.deviceId(deviceTableVO1.getDeviceId())
						.deviceChannelId(deviceTableVO1.getDeviceChannelId()).propertieId("ccd3_x_after").propertieName("CCD3-脉冲后沿-X向位移").build());

					onceValueVOList.add( OnceValueVO.builder().onceValue("0")
						.deviceName(deviceTableVO1.getDeviceName())
						.deviceId(deviceTableVO1.getDeviceId())
						.deviceChannelId(deviceTableVO1.getDeviceChannelId()).propertieId("ccd1_y_front").propertieName("CCD1-脉冲前沿-Y向位移").build());

					onceValueVOList.add( OnceValueVO.builder().onceValue("0")
						.deviceName(deviceTableVO1.getDeviceName())
						.deviceId(deviceTableVO1.getDeviceId())
						.deviceChannelId(deviceTableVO1.getDeviceChannelId()).propertieId("ccd1_y_after").propertieName("CCD1-脉冲后沿-Y向位移").build());
				}else {
					DeviceTable deviceTableVO26 = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda()
						.eq(DeviceTable::getDeviceChannelId,26).eq(DeviceTable::getIsDeleted, 0));

					DeviceRuningStateDTO.DeviceListDTO deviceListDTO3 = deviceList.stream().filter(l1 -> l1.getDeviceId().equals("26")).findFirst().orElse(null);
					DeviceRuningStateDTO.DeviceListDTO deviceListDTO4 = deviceList.stream().filter(l1 -> l1.getDeviceId().equals("25")).findFirst().orElse(null);
					onceValueVOList.add( OnceValueVO.builder().onceValue(deviceListDTO3.getAttributeListDTO().get(0).getValue().toString())
						.deviceName(deviceTableVO26.getDeviceName())
						.deviceId(deviceTableVO26.getDeviceId())
						.deviceChannelId(deviceTableVO26.getDeviceChannelId()).propertieId("x26").propertieName("读数").build());

					DeviceTable deviceTableVO5 = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda()
						.eq(DeviceTable::getDeviceChannelId,25).eq(DeviceTable::getIsDeleted, 0));
					onceValueVOList.add( OnceValueVO.builder().onceValue(deviceListDTO4.getAttributeListDTO().get(0).getValue().toString())
						.deviceName(deviceTableVO5.getDeviceName())
						.deviceId(deviceTableVO5.getDeviceId())
						.deviceChannelId(deviceTableVO5.getDeviceChannelId()).propertieId("y25").propertieName("读数").build());


					DeviceTable deviceTableVO28 = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda()
						.eq(DeviceTable::getDeviceChannelId,28).eq(DeviceTable::getIsDeleted, 0));
					DeviceTable deviceTableVO27 = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda()
						.eq(DeviceTable::getDeviceChannelId,27).eq(DeviceTable::getIsDeleted, 0));
					DeviceRuningStateDTO.DeviceListDTO deviceListDTO27 = deviceList.stream().filter(l -> l.getDeviceId().equals("28")).findFirst().orElse(null);
					DeviceRuningStateDTO.DeviceListDTO deviceListDTO28 = deviceList.stream().filter(l -> l.getDeviceId().equals("27")).findFirst().orElse(null);


					onceValueVOList.add( OnceValueVO.builder().onceValue(deviceListDTO27.getAttributeListDTO().get(0).getValue().toString())
						.deviceName(deviceTableVO27.getDeviceName())
						.deviceId(deviceTableVO27.getDeviceId())
						.deviceChannelId(deviceTableVO27.getDeviceChannelId()).propertieId("y27").propertieName("读数").build());

					onceValueVOList.add( OnceValueVO.builder().onceValue(deviceListDTO28.getAttributeListDTO().get(0).getValue().toString())
						.deviceName(deviceTableVO28.getDeviceName())
						.deviceId(deviceTableVO28.getDeviceId())
						.deviceChannelId(deviceTableVO28.getDeviceChannelId()).propertieId("x28").propertieName("读数").build());

					DeviceTable deviceTableVO29 = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda()
						.eq(DeviceTable::getDeviceChannelId,29).eq(DeviceTable::getIsDeleted, 0));
					DeviceTable deviceTableVO30 = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda()
						.eq(DeviceTable::getDeviceChannelId,30).eq(DeviceTable::getIsDeleted, 0));
					DeviceRuningStateDTO.DeviceListDTO deviceListDTO29 = deviceList.stream().filter(l -> l.getDeviceId().equals("29")).findFirst().orElse(null);
					DeviceRuningStateDTO.DeviceListDTO deviceListDTO30 = deviceList.stream().filter(l -> l.getDeviceId().equals("30")).findFirst().orElse(null);

					onceValueVOList.add( OnceValueVO.builder().onceValue(deviceListDTO29.getAttributeListDTO().get(0).getValue().toString())
						.deviceName(deviceTableVO29.getDeviceName())
						.deviceId(deviceTableVO29.getDeviceId())
						.deviceChannelId(deviceTableVO29.getDeviceChannelId()).propertieId("x29").propertieName("读数").build());

					onceValueVOList.add( OnceValueVO.builder().onceValue(deviceListDTO30.getAttributeListDTO().get(0).getValue().toString())
						.deviceName(deviceTableVO30.getDeviceName())
						.deviceId(deviceTableVO30.getDeviceId())
						.deviceChannelId(deviceTableVO30.getDeviceChannelId()).propertieId("y30").propertieName("读数").build());


					DeviceTable deviceTableVO32 = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda()
						.eq(DeviceTable::getDeviceChannelId,32).eq(DeviceTable::getIsDeleted, 0));
					DeviceTable deviceTableVO31 = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda()
						.eq(DeviceTable::getDeviceChannelId,31).eq(DeviceTable::getIsDeleted, 0));

					DeviceRuningStateDTO.DeviceListDTO deviceListDTO32 = deviceList.stream().filter(l -> l.getDeviceId().equals("32")).findFirst().orElse(null);
					DeviceRuningStateDTO.DeviceListDTO deviceListDTO31 = deviceList.stream().filter(l -> l.getDeviceId().equals("31")).findFirst().orElse(null);
					onceValueVOList.add( OnceValueVO.builder().onceValue(deviceListDTO32.getAttributeListDTO().get(0).getValue().toString())
						.deviceName(deviceTableVO32.getDeviceName())
						.deviceId(deviceTableVO32.getDeviceId())
						.deviceChannelId(deviceTableVO32.getDeviceChannelId()).propertieId("x32").propertieName("读数").build());

					onceValueVOList.add( OnceValueVO.builder().onceValue(deviceListDTO31.getAttributeListDTO().get(0).getValue().toString())
						.deviceName(deviceTableVO31.getDeviceName())
						.deviceId(deviceTableVO31.getDeviceId())
						.deviceChannelId(deviceTableVO31.getDeviceChannelId()).propertieId("y31").propertieName("读数").build());

					DeviceTable deviceTableVO33 = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda()
						.eq(DeviceTable::getDeviceChannelId,33).eq(DeviceTable::getIsDeleted, 0));
					DeviceTable deviceTableVO34 = iDeviceTableService.getOne(Wrappers.<DeviceTable>query().lambda()
						.eq(DeviceTable::getDeviceChannelId,34).eq(DeviceTable::getIsDeleted, 0));

					DeviceRuningStateDTO.DeviceListDTO deviceListDTO33 = deviceList.stream().filter(l -> l.getDeviceId().equals("33")).findFirst().orElse(null);
					DeviceRuningStateDTO.DeviceListDTO deviceListDTO34 = deviceList.stream().filter(l -> l.getDeviceId().equals("34")).findFirst().orElse(null);
					onceValueVOList.add( OnceValueVO.builder().onceValue(deviceListDTO33.getAttributeListDTO().get(0).getValue().toString())
						.deviceName(deviceTableVO34.getDeviceName())
						.deviceId(deviceTableVO34.getDeviceId())
						.deviceChannelId(deviceTableVO34.getDeviceChannelId()).propertieId("x34").propertieName("读数").build());

					onceValueVOList.add( OnceValueVO.builder().onceValue(deviceListDTO34.getAttributeListDTO().get(0).getValue().toString())
						.deviceName(deviceTableVO33.getDeviceName())
						.deviceId(deviceTableVO33.getDeviceId())
						.deviceChannelId(deviceTableVO33.getDeviceChannelId()).propertieId("y33").propertieName("读数").build());

				}
			}
			EquipmentRuningState equipmentRuningState4 = new EquipmentRuningState();
			equipmentRuningState4.setEquipmentId(deviceTableVO.getDeviceId());
			equipmentRuningState4.setInsertTime(gatherTime);
			equipmentRuningState4.setUpdateTime(gatherTime);
			ProductModelProperties productModelProperties = productModelPropertiesService.getOne(new QueryWrapper<ProductModelProperties>().lambda()
				.eq(ProductModelProperties::getProductId,deviceTableVO.getProductId()));
			String propertiesJson = productModelProperties.getPropertiesJson();
			JSONArray jsonArray = JSONArray.parseArray(propertiesJson);
			JSONObject jsonObject = new JSONObject();
			List<DeviceRuningStateDTO.DeviceListDTO.AttributeListDTO> attributeListDTO = deviceListDTO.getAttributeListDTO();
			if(Func.isEmpty(attributeListDTO)){
				return onceValueVOList;
			}
			attributeListDTO.forEach(l->{
				EquipmentRuningState equipmentRuningState1 = new EquipmentRuningState();
				equipmentRuningState1.setEquipmentId(deviceTableVO.getDeviceId());
				equipmentRuningState1.setInsertTime(gatherTime);
				equipmentRuningState1.setUpdateTime(gatherTime);
				equipmentRuningState1.setPropertieId(l.getKey());
				Map<String, Object> map = new HashMap<>();
				map.put(l.getKey(), l.getValue());
				equipmentRuningState1.setJsonText(JSONObject.toJSONString(map));
				iEquipmentRuningStateService.remove(Wrappers.<EquipmentRuningState>query().lambda().eq(EquipmentRuningState::getEquipmentId, deviceTableVO.getDeviceId()).eq(EquipmentRuningState::getPropertieId, l.getKey()));
				iEquipmentRuningStateService.save(equipmentRuningState1);
				jsonObject.put(l.getKey(), l.getValue());

				String propertieName = null;
				Optional<Object> id = jsonArray.stream().filter(j -> ((JSONObject) j).get("id").toString().equalsIgnoreCase(l.getKey())).findFirst();
				if(id.isPresent()){
					JSONObject o = (JSONObject) id.get();
					propertieName = o.get("name").toString();
				}
				onceValueVOList.add( OnceValueVO.builder().onceValue(String.valueOf(l.getValue()))
					.deviceName(deviceTableVO.getDeviceName())
					.deviceId(deviceTableVO.getDeviceId())
					.deviceChannelId(deviceTableVO.getDeviceChannelId()).propertieId(l.getKey()).propertieName(propertieName).build());
			});
			equipmentRuningState4.setJsonText(jsonObject.toJSONString());
			iEquipmentRuningStateService.insertEquipmentRuningState(equipmentRuningState4);
			return onceValueVOList;
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;


	}

	private Double getModelData(List<Integer> x, List<SysParameter> sysParameterList,PhysicalQuantityEnum physicalQuantityEnum){
		try {


			log.info("标定系数physicalQuantityEnum:{}",physicalQuantityEnum);
			log.info("CCD值:{}",x);
			log.info("标定系数sysParameterList:{}",sysParameterList);

			Double collect = x.stream().collect(Collectors.averagingDouble(item -> item));
			SysParameter first = sysParameterList.stream().filter(l ->
				l.getParameterKey().equals(physicalQuantityEnum.getCode())
					&& l.getMinValue() <= collect
					&& l.getMaxValue() > collect).findFirst().get();
			double v = first.getDipXK() * collect + first.getDipXB();
			BigDecimal bigDecimal = new BigDecimal(v).setScale(14, RoundingMode.DOWN);
			return bigDecimal.doubleValue();
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;

	}

	private Double getModelData2(Double x, List<SysParameter> sysParameterList,PhysicalQuantityEnum physicalQuantityEnum){
		try {

			log.info("标定系数physicalQuantityEnum:{}",physicalQuantityEnum);
			log.info("CCD值:{}",x);
			log.info("标定系数sysParameterList:{}",sysParameterList);
			SysParameter first = sysParameterList.stream().filter(l ->
				l.getParameterKey().equals(physicalQuantityEnum.getCode())
					&& l.getMinValue() <= x
					&& l.getMaxValue() > x).findFirst().get();
			double v = first.getDipXK() * x + first.getDipXB();
			BigDecimal bigDecimal = new BigDecimal(v).setScale(14, RoundingMode.DOWN);
			return bigDecimal.doubleValue();
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;

	}


	private void pullData(BigDecimal d,String str,String connectionId,Integer code){
		try {
			if(StringUtils.isEmpty(connectionId)){
				return;
			}
			ChannelGroup channels = WebSokcetChannelGroup.channels;
			Map<String, List<String>> map = WebSokcetChannelGroup.MAP;
			if(map.containsKey("COLLECT_DATA")){
				List<String> stringList = map.get("COLLECT_DATA");
				if(Func.isEmpty(stringList)){
					return;
				}
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("proportion",d);
				jsonObject.put("msg",str);
				jsonObject.put("code",code);
				Optional<Channel> first = channels.stream().filter(x ->x.attr(CONNECTION_ID).get().contains(connectionId)).findFirst();
				if(first.isPresent()){
					ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
					channelGroup.add(first.get());
					log.info("推送数据:{}",JSONObject.toJSONString(jsonObject));
					channelGroup.writeAndFlush(new TextWebSocketFrame(JSONObject.toJSONString(jsonObject)));
				}
			}
		}catch (Exception e){
			log.info("推送数据异常");

		}
	}
	public List<Double> getDobleMath2(Integer x1,Integer x2,Integer x3,Integer x4){
		try {

			Double abs = (double) Math.abs(x1 - x3);
			Double abs1 = (double) Math.abs(x2 - x4);
			Double collect1 = Stream.of(x1, x2).collect(Collectors.averagingDouble(item -> item));
			Double collect2 = Stream.of(x3, x4).collect(Collectors.averagingDouble(item -> item));
			Double collect = Math.abs(collect1 - collect2);
			Double min = Collections.min( Arrays.asList(abs, abs1,collect));
			if(abs.equals(min)){
				return Arrays.asList((double) x1,(double) x3);
			}else  if(abs1.equals(min)){
				return Arrays.asList((double) x2,(double) x4);
			}else {
				return Arrays.asList(collect1,collect2);
			}
		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;

	}
	public Double getDobleMath(Double x1,Double x2,Double x3){
		try {
			Double min = Collections.min(Arrays.asList(Math.abs(x1), Math.abs(x2), Math.abs(x3)));
			if(Math.abs(x1)==min){
				return x1;
			}else if(Math.abs(x2)==min){
				return x2;
			}else {
				return x3;
			}

		}catch (Exception e){
			bladeRedis.del("ACTIVE_QUERY");
		}
		return null;

	}

}
